MCPcopy Create free account
hub / github.com/chrxh/alien / compareGenomeColorMutation

Method compareGenomeColorMutation

source/EngineTests/MutationTests.cpp:615–650  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

613 }
614
615 bool compareGenomeColorMutation(std::vector<uint8_t> const& before, std::vector<uint8_t> const& after, std::optional<int> const& allowedColor)
616 {
617 auto beforeGenome = GenomeDescriptionService::get().convertBytesToDescription(before);
618 auto afterGenome = GenomeDescriptionService::get().convertBytesToDescription(after);
619 if (afterGenome.header != beforeGenome.header) {
620 return false;
621 }
622
623 int uniformColor = allowedColor ? *allowedColor : afterGenome.cells.at(0).color;
624 for (auto const& [beforeCell, afterCell] : boost::combine(beforeGenome.cells, afterGenome.cells)) {
625
626 auto beforeCellClone = beforeCell;
627 auto afterCellClone = afterCell;
628 beforeCellClone.color = 0;
629 beforeCellClone.cellFunction = std::nullopt;
630 afterCellClone.color = 0;
631 afterCellClone.cellFunction = std::nullopt;
632 if (beforeCellClone != afterCellClone) {
633 return false;
634 }
635 if (afterCell.color != uniformColor) {
636 return false;
637 }
638 uniformColor = afterCell.color;
639 if (beforeCell.getCellFunctionType() == CellFunction_Constructor || beforeCell.getCellFunctionType() == CellFunction_Injector) {
640 auto beforeSubGenome = beforeCell.getGenome();
641 auto afterSubGenome = afterCell.getGenome();
642 if (beforeSubGenome && afterSubGenome) {
643 if (!compareGenomeColorMutation(*beforeSubGenome, *afterSubGenome, uniformColor)) {
644 return false;
645 }
646 }
647 }
648 }
649 return true;
650 }
651};
652
653TEST_F(MutationTests, propertiesMutation)

Callers

nothing calls this directly

Calls 3

getGenomeMethod · 0.80
getCellFunctionTypeMethod · 0.45

Tested by

no test coverage detected