public void WhenGraphNodeIsDependentOnOther_ObserverIsSetCorrectly() { // arrange var workSheet = new WorkSheetGraph(new Spreadsheet(), 2, 4); // act workSheet.SetCellFormula("A1", "A2 B2 / 2 +"); workSheet.SetCellFormula("A2", "A3 B2 / 2 +"); workSheet.SetCellFormula("A3", "A4 B2 / 2 +"); var cellA1 = workSheet.GetCell("A1"); var cellA2 = workSheet.GetCell("A2"); var cellA3 = workSheet.GetCell("A3"); var cellA4 = workSheet.GetCell("A4"); var cellB2 = workSheet.GetCell("B2"); var observersB2 = cellB2.Observers.GetAll(); var observersA4 = cellA4.Observers.GetAll(); var observersA3 = cellA3.Observers.GetAll(); var observersA2 = cellA2.Observers.GetAll(); var observersA1 = cellA1.Observers.GetAll(); // assert Assert.AreEqual(observersB2.Count, 3); Assert.AreEqual(observersA1.Count, 0); Assert.AreEqual(observersA2.Count, 1); Assert.AreEqual(observersA3.Count, 1); Assert.AreEqual(observersA4.Count, 1); }
public void WhenMultiLevelFormulaIsPassed_AdjacacencyEdgesArePopulatedCorrectly() { // arrange var workSheet = new WorkSheetGraph(new Spreadsheet(), 2, 4); // act workSheet.SetCellFormula("A1", "A2 B2 / 2 +"); workSheet.SetCellFormula("A2", "A3 B2 / 2 +"); workSheet.SetCellFormula("A3", "A4 B2 / 2 +"); var cellA1 = workSheet.GetCell("A1"); var cellA2 = workSheet.GetCell("A2"); var cellA3 = workSheet.GetCell("A3"); var cellA4 = workSheet.GetCell("A4"); var cellB2 = workSheet.GetCell("B2"); // assert Assert.AreEqual(2, cellA1.Edges.Count); Assert.AreEqual(2, cellA2.Edges.Count); Assert.AreEqual(2, cellA3.Edges.Count); Assert.AreEqual(0, cellA4.Edges.Count); Assert.AreEqual(0, cellB2.Edges.Count); Assert.AreEqual("A2", cellA1.Edges[0].Name); Assert.AreEqual("B2", cellA1.Edges[1].Name); Assert.AreEqual("A3", cellA2.Edges[0].Name); Assert.AreEqual("B2", cellA2.Edges[1].Name); Assert.AreEqual("A4", cellA3.Edges[0].Name); Assert.AreEqual("B2", cellA3.Edges[1].Name); }
public void WhenFormulaHasNoCyclicDepedency_NoExceptionShouldBeThrown() { // arrange var workSheet = new WorkSheetGraph(new Spreadsheet(), 5, 5); // act workSheet.SetCellFormula("A1", "A2 B2 / 2 +"); workSheet.SetCellFormula("A2", "A3 B2 / 2 +"); workSheet.SetCellFormula("A3", "A4 B2 / 2 +"); // no assert needed as the test is to check if exception is not raised. }
public void WhenFormulaHasCyclicDepedency_ThrowsCyclicDependencyException() { // arrange var workSheet = new WorkSheetGraph(new Spreadsheet(), 3, 3); // act and assert workSheet.SetCellFormula("A1", "A2 B2 / 2 +"); Assert.ThrowsException <CyclicDependencyException>( () => workSheet.SetCellFormula("A2", "A1 B2 / 2 +") ); }
public void WhenFormulaHasMultiLevelCyclicDepedency_CyclicDependencyExceptionIsThrown() { // arrange var workSheet = new WorkSheetGraph(new Spreadsheet(), 5, 5); // act and assert workSheet.SetCellFormula("A1", "A2 B2 / 2 +"); workSheet.SetCellFormula("A2", "A3 B2 / 2 +"); Assert.ThrowsException <CyclicDependencyException>( () => workSheet.SetCellFormula("A3", "A1 B2 / 2 +") ); }
public void WhenNumericFormulaIsPassed_AdjacacencyEdgesShouldNotPopulate() { // arrange var workSheet = new WorkSheetGraph(new Spreadsheet(), 3, 3); // act workSheet.SetCellFormula("A1", "A2"); workSheet.SetCellFormula("A2", "4 5 *"); var cellA1 = workSheet.GetCell("A1"); var cellA2 = workSheet.GetCell("A2"); // assert Assert.AreEqual(1, cellA1.Edges.Count); Assert.AreEqual("A2", cellA1.Edges[0].Name); Assert.AreEqual(0, cellA2.Edges.Count); }
public void WhenSimpleFormulaIsPassed_AdjacacencyEdgesArePopulatedCorrectly() { // arrange var workSheet = new WorkSheetGraph(new Spreadsheet(), 3, 3); // act workSheet.SetCellFormula("A1", "A2 B2 / 2 +"); var cell = workSheet.GetCell("A1"); // assert Assert.AreEqual(2, cell.Edges.Count); Assert.AreEqual("A2", cell.Edges[0].Name); Assert.AreEqual("B2", cell.Edges[1].Name); }
public void WhenGraphNodeIsDependentOnOther_ObserverIsEvaluatedCorrectly() { // arrange var workSheet = new WorkSheetGraph(new Spreadsheet(), 2, 4); // act workSheet.SetCellFormula("A1", "A2"); workSheet.SetCellFormula("A2", "10"); var cellA1 = workSheet.GetCell("A1"); var cellA2 = workSheet.GetCell("A2"); var observersA2 = cellA2.Observers.GetAll(); var observersA1 = cellA1.Observers.GetAll(); // assert Assert.AreEqual(0, observersA1.Count); Assert.AreEqual(1, observersA2.Count); Assert.AreEqual(10, cellA2.Value); Assert.AreEqual(10, cellA1.Value); }
public void WhenFormulaIsComplexButNoCyclicDepedency_NoExceptionShouldBeThrown() { // arrange var workSheet = new WorkSheetGraph(new Spreadsheet(), 5, 5); // act and assert (given input) workSheet.SetCellFormula("A1", "A2"); workSheet.SetCellFormula("A2", "4 5 *"); workSheet.SetCellFormula("A3", "A1"); workSheet.SetCellFormula("B1", "A1 B2 / 2 +"); workSheet.SetCellFormula("B2", "3"); workSheet.SetCellFormula("B3", "39 B1 B2 * /"); // no assert needed as the test is to check if exception is not raised. }