| 74 | } |
| 75 | |
| 76 | std::string areJsonEqual(json lhs, json rhs) { |
| 77 | std::string errstring; |
| 78 | |
| 79 | errstring = areArrayEqualUnordered(lhs["dependencies"], rhs["dependencies"]); |
| 80 | if (!errstring.empty()) return "dependencies not equal: " + errstring; |
| 81 | |
| 82 | auto& lgraphs = lhs["graphs"]; |
| 83 | auto& rgraphs = rhs["graphs"]; |
| 84 | |
| 85 | if (lgraphs.size() != rgraphs.size()) return "different number of graphs"; |
| 86 | |
| 87 | for (size_t iter = 0; iter != lgraphs.size(); ++iter) { |
| 88 | auto& lgraph = lgraphs[0]; |
| 89 | auto& rgraph = rgraphs[0]; |
| 90 | |
| 91 | errstring = areArrayEqualUnordered(lgraph["connections"], rgraph["connections"]); |
| 92 | if (!errstring.empty()) |
| 93 | return "connections not equal in graph #" + std::to_string(iter) + " " + errstring; |
| 94 | |
| 95 | if (lgraph["name"] != rgraph["name"]) { |
| 96 | return "graph name in graph #" + std::to_string(iter) + |
| 97 | " not equal; serialized: " + lgraph["name"].dump(-1) + |
| 98 | " original: " + rgraph["name"].dump(-1); |
| 99 | } |
| 100 | if (lgraph["description"] != rgraph["description"]) { |
| 101 | return "graph description in graph #" + std::to_string(iter) + |
| 102 | " not equal; serialized: " + lgraph["description"].dump(-1) + |
| 103 | " original: " + rgraph["description"].dump(-1); |
| 104 | } |
| 105 | // compare nodes |
| 106 | for (auto nodeIter = lgraph["nodes"].begin(); nodeIter != lgraph["nodes"].end(); |
| 107 | ++nodeIter) { |
| 108 | auto& lnode = nodeIter.value(); |
| 109 | auto& rnode = rgraph["nodes"][nodeIter.key()]; |
| 110 | if (abs(float(lnode["location"][0]) - float(rnode["location"][0])) >= .00001) { |
| 111 | return "node with id: " + nodeIter.key() + " in graph #" + std::to_string(iter) + |
| 112 | " has a non-matching x location. Original: " + |
| 113 | std::to_string(float(lnode["location"][0])) + |
| 114 | " Serialized: " + std::to_string(float(rnode["location"][0])); |
| 115 | } |
| 116 | |
| 117 | if (abs(float(lnode["location"][1]) - float(rnode["location"][1])) >= .00001) { |
| 118 | return "node with id: " + nodeIter.key() + " in graph #" + std::to_string(iter) + |
| 119 | " has a non-matching y location. Original: " + |
| 120 | std::to_string(float(lnode["location"][1])) + |
| 121 | " Serialized: " + std::to_string(float(rnode["location"][1])); |
| 122 | } |
| 123 | |
| 124 | if (lnode["data"] != rnode["data"]) { |
| 125 | return "node with id: " + nodeIter.key() + " in graph #" + std::to_string(iter) + |
| 126 | " have non-matching data. Original: \n\n" + rnode["data"].dump(-1) + |
| 127 | "\n\nSerialized: \n\n" + lnode["data"].dump(-1); |
| 128 | } |
| 129 | |
| 130 | if (lnode["type"] != rnode["type"]) { |
| 131 | return "node with id: " + nodeIter.key() + " in graph #" + std::to_string(iter) + |
| 132 | " have non-matching types. Original: \n\n" + rnode["type"].dump(-1) + |
| 133 | "\n\nSerialized: \n\n" + lnode["type"].dump(-1); |