def test_results_diff(self, test_client): dataset1 = MatrixDataset(ma.masked_values([[1, 0], [0, 2]], 0)) dataset2 = MatrixDataset(ma.masked_values([[1, 2], [0, 2]], 0)) request_data1 = {"algorithm": "voting", "matrix": dataset1.to_csv()} resp1 = test_client.get("/run/", query_string=request_data1) assert resp1.status_code == 200 request_data2 = { # Test diffs with multiple algorithms "algorithm": ["voting", "investment"], "matrix": dataset2.to_csv(), "previous_results": json.dumps(resp1.json["data"]["voting"]) } resp2 = test_client.get("/run/", query_string=request_data2) assert resp2.status_code == 200 vot_out = resp2.json["data"]["voting"] assert "diff" in vot_out assert vot_out["diff"]["trust"] == {"0": 0, "1": 0} # no trust changes assert vot_out["diff"]["belief"] == { "0": { "1.0": -0.5 }, "1": { "2.0": 0 } } inv_out = resp2.json["data"]["investment"] assert "diff" in inv_out assert inv_out["diff"]["trust"] == {"0": -0.7731216864273125, "1": 0.0} assert inv_out["diff"]["belief"] == { "0": { "1.0": -0.9354768146506873 }, "1": { "2.0": 0.0 } }
def test_export_to_csv(self): data = MatrixDataset( ma.masked_values( [ # All full row [1, 2, 3, 4, 5, 6, 7, 8], # Mixed row [1, 2, 0, -123, 4, -2.3, 99.123, -123], # All empty row [-123, -123, -123, -123, -123, -123, -123, -123] ], -123)) expected = "\n".join(("1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0", "1.0,2.0,0.0,,4.0,-2.3,99.123,", ",,,,,,,")) assert data.to_csv() == expected