diff --git a/ganttzk/src/test/java/org/zkoss/ganttz/data/criticalpath/CriticalPathCalculatorTest.java b/ganttzk/src/test/java/org/zkoss/ganttz/data/criticalpath/CriticalPathCalculatorTest.java
index 1761af56e..62e2bb115 100644
--- a/ganttzk/src/test/java/org/zkoss/ganttz/data/criticalpath/CriticalPathCalculatorTest.java
+++ b/ganttzk/src/test/java/org/zkoss/ganttz/data/criticalpath/CriticalPathCalculatorTest.java
@@ -841,6 +841,222 @@ public class CriticalPathCalculatorTest {
replay(diagramGraphExample);
}
+ /**
+ *
+ * #### T1 #### -|
+ * |
+ * #### T2 #### -|
+ *
+ */
+ private void givenPairOfTasksEndEnd(int daysTask1, int daysTask2) {
+ diagramGraphExample = createNiceMock(ICriticalPathCalculable.class);
+
+ ITaskFundamentalProperties task1 = createTask(START, daysTask1);
+ ITaskFundamentalProperties task2 = createTask(START, daysTask2);
+
+ List listOfTasks = Arrays.asList(task1,
+ task2);
+
+ expect(diagramGraphExample.getTasks()).andReturn(listOfTasks)
+ .anyTimes();
+ expect(diagramGraphExample.getInitialTasks()).andReturn(
+ Arrays.asList(task1, task2)).anyTimes();
+ expect(diagramGraphExample.getLatestTasks()).andReturn(
+ Arrays.asList(task2)).anyTimes();
+
+ IDependency dependency = createDependency(
+ task1, task2, DependencyType.END_END);
+ expect(diagramGraphExample.getDependencyFrom(task1, task2)).andReturn(
+ dependency).anyTimes();
+
+ expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn(
+ new HashSet()).anyTimes();
+ expect(diagramGraphExample.getIncomingTasksFor(task2)).andReturn(
+ new HashSet(Arrays.asList(task1)))
+ .anyTimes();
+ expect(diagramGraphExample.getOutgoingTasksFor(task1)).andReturn(
+ new HashSet(Arrays.asList(task2)))
+ .anyTimes();
+ expect(diagramGraphExample.getOutgoingTasksFor(task2)).andReturn(
+ new HashSet()).anyTimes();
+
+ replay(diagramGraphExample);
+ }
+
+ /**
+ *
+ * |---- #### S1 ####
+ * |
+ * #### T1 #### -|
+ * |
+ * #### T2 #### -|
+ *
+ */
+ private void givenPairOfTasksEndEndFirstOfThemWithOneSubtask(int daysTask1,
+ int daysSubtask1, int daysTask2) {
+ diagramGraphExample = createNiceMock(ICriticalPathCalculable.class);
+
+ ITaskFundamentalProperties task1 = createTask(START, daysTask1);
+ ITaskFundamentalProperties subtask1 = createTask(START, daysSubtask1);
+ ITaskFundamentalProperties task2 = createTask(START, daysTask2);
+
+ List listOfTasks = Arrays.asList(task1,
+ subtask1, task2);
+
+ expect(diagramGraphExample.getTasks()).andReturn(listOfTasks)
+ .anyTimes();
+ expect(diagramGraphExample.getInitialTasks()).andReturn(
+ Arrays.asList(task1, task2)).anyTimes();
+ expect(diagramGraphExample.getLatestTasks()).andReturn(
+ Arrays.asList(task2, subtask1)).anyTimes();
+
+ IDependency dependency = createDependency(
+ task1, task2, DependencyType.END_END);
+ expect(diagramGraphExample.getDependencyFrom(task1, task2)).andReturn(
+ dependency).anyTimes();
+
+ expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn(
+ new HashSet()).anyTimes();
+ expect(diagramGraphExample.getIncomingTasksFor(subtask1)).andReturn(
+ new HashSet(Arrays.asList(task1)))
+ .anyTimes();
+ expect(diagramGraphExample.getIncomingTasksFor(task2)).andReturn(
+ new HashSet(Arrays.asList(task1)))
+ .anyTimes();
+ expect(diagramGraphExample.getOutgoingTasksFor(task1)).andReturn(
+ new HashSet(Arrays.asList(subtask1,
+ task2))).anyTimes();
+ expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn(
+ new HashSet()).anyTimes();
+ expect(diagramGraphExample.getOutgoingTasksFor(task2)).andReturn(
+ new HashSet()).anyTimes();
+
+ replay(diagramGraphExample);
+ }
+
+ /**
+ *
+ * #### T1 ####
+ * |---- #### S1 #### -|
+ * |
+ * #### T2 #### |
+ * |---- #### S2 #### -|
+ *
+ */
+ private void givenTwoTasksWithSubtasksRelatedWithEndEnd(int daysTask1,
+ int daysSubtask1, int daysTask2, int daysSubtask2) {
+ diagramGraphExample = createNiceMock(ICriticalPathCalculable.class);
+
+ ITaskFundamentalProperties task1 = createTask(START, daysTask1);
+ ITaskFundamentalProperties subtask1 = createTask(START, daysSubtask1);
+ ITaskFundamentalProperties task2 = createTask(START, daysTask2);
+ ITaskFundamentalProperties subtask2 = createTask(START, daysSubtask2);
+
+ List listOfTasks = Arrays.asList(task1,
+ subtask1, task2, subtask2);
+
+ expect(diagramGraphExample.getTasks()).andReturn(listOfTasks)
+ .anyTimes();
+ expect(diagramGraphExample.getInitialTasks()).andReturn(
+ Arrays.asList(task1, task2)).anyTimes();
+ expect(diagramGraphExample.getLatestTasks()).andReturn(
+ Arrays.asList(subtask2)).anyTimes();
+
+ IDependency dependency = createDependency(
+ subtask1, subtask2, DependencyType.END_END);
+ expect(diagramGraphExample.getDependencyFrom(subtask1, subtask2))
+ .andReturn(dependency).anyTimes();
+
+ expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn(
+ new HashSet()).anyTimes();
+ expect(diagramGraphExample.getIncomingTasksFor(subtask1)).andReturn(
+ new HashSet(Arrays.asList(task1)))
+ .anyTimes();
+ expect(diagramGraphExample.getIncomingTasksFor(task2)).andReturn(
+ new HashSet()).anyTimes();
+ expect(diagramGraphExample.getIncomingTasksFor(subtask2)).andReturn(
+ new HashSet(Arrays.asList(task2,
+ subtask1))).anyTimes();
+ expect(diagramGraphExample.getOutgoingTasksFor(task1))
+ .andReturn(
+ new HashSet(Arrays
+ .asList(subtask1))).anyTimes();
+ expect(diagramGraphExample.getOutgoingTasksFor(subtask1))
+ .andReturn(
+ new HashSet(Arrays
+ .asList(subtask2))).anyTimes();
+ expect(diagramGraphExample.getOutgoingTasksFor(task2))
+ .andReturn(
+ new HashSet(Arrays
+ .asList(subtask2))).anyTimes();
+ expect(diagramGraphExample.getOutgoingTasksFor(subtask2)).andReturn(
+ new HashSet()).anyTimes();
+
+ replay(diagramGraphExample);
+ }
+
+ /**
+ *
+ * #### T1 ####
+ * |
+ * |---- #### S1 ####
+ * |
+ * |---- #### S2 #### -|
+ * |
+ * #### S3 #### -|
+ *
+ */
+ private void givenExampleEndEnd(int daysTask1, int daysSubtask1,
+ int daysSubtask2, int daysSubtask3) {
+ diagramGraphExample = createNiceMock(ICriticalPathCalculable.class);
+
+ ITaskFundamentalProperties task1 = createTask(START, daysTask1);
+ ITaskFundamentalProperties subtask1 = createTask(START, daysSubtask1);
+ ITaskFundamentalProperties subtask2 = createTask(START, daysSubtask2);
+ ITaskFundamentalProperties subtask3 = createTask(START, daysSubtask3);
+
+ List listOfTasks = Arrays.asList(task1,
+ subtask1, subtask2, subtask3);
+
+ expect(diagramGraphExample.getTasks()).andReturn(listOfTasks)
+ .anyTimes();
+ expect(diagramGraphExample.getInitialTasks()).andReturn(
+ Arrays.asList(task1, subtask3)).anyTimes();
+ expect(diagramGraphExample.getLatestTasks()).andReturn(
+ Arrays.asList(subtask1, subtask3)).anyTimes();
+
+ IDependency dependency = createDependency(
+ subtask2, subtask3, DependencyType.END_END);
+ expect(diagramGraphExample.getDependencyFrom(subtask2, subtask3))
+ .andReturn(dependency).anyTimes();
+
+ expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn(
+ new HashSet()).anyTimes();
+ expect(diagramGraphExample.getIncomingTasksFor(subtask1)).andReturn(
+ new HashSet(Arrays.asList(task1)))
+ .anyTimes();
+ expect(diagramGraphExample.getIncomingTasksFor(subtask2)).andReturn(
+ new HashSet(Arrays.asList(task1)))
+ .anyTimes();
+ expect(diagramGraphExample.getIncomingTasksFor(subtask3))
+ .andReturn(
+ new HashSet(Arrays
+ .asList(subtask2))).anyTimes();
+ expect(diagramGraphExample.getOutgoingTasksFor(task1)).andReturn(
+ new HashSet(Arrays.asList(subtask1,
+ subtask2))).anyTimes();
+ expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn(
+ new HashSet()).anyTimes();
+ expect(diagramGraphExample.getOutgoingTasksFor(subtask2))
+ .andReturn(
+ new HashSet(Arrays
+ .asList(subtask3))).anyTimes();
+ expect(diagramGraphExample.getOutgoingTasksFor(subtask3)).andReturn(
+ new HashSet()).anyTimes();
+
+ replay(diagramGraphExample);
+ }
+
@Test
public void trivialBaseCase() {
givenOneTask(10);
@@ -1208,4 +1424,115 @@ public class CriticalPathCalculatorTest {
}
}
+ @Test
+ public void pairOfTasksEndEnd() {
+ givenPairOfTasksEndEnd(10, 5);
+ List criticalPath = new CriticalPathCalculator()
+ .calculateCriticalPath(diagramGraphExample);
+
+ assertThat(criticalPath.size(), equalTo(2));
+ for (ITaskFundamentalProperties task : criticalPath) {
+ assertThat(toDays(task.getLengthMilliseconds()), anyOf(equalTo(10),
+ equalTo(5)));
+ }
+ }
+
+ @Test
+ public void pairOfTasksEndEnd2() {
+ givenPairOfTasksEndEnd(5, 10);
+ List criticalPath = new CriticalPathCalculator()
+ .calculateCriticalPath(diagramGraphExample);
+
+ assertThat(criticalPath.size(), equalTo(1));
+ assertThat(toDays(criticalPath.get(0).getLengthMilliseconds()),
+ equalTo(10));
+ }
+
+ @Test
+ public void pairOfTasksEndEndFirstOfThemWithOneSubtask() {
+ givenPairOfTasksEndEndFirstOfThemWithOneSubtask(4, 3, 2);
+ List criticalPath = new CriticalPathCalculator()
+ .calculateCriticalPath(diagramGraphExample);
+
+ assertThat(criticalPath.size(), equalTo(2));
+ for (ITaskFundamentalProperties task : criticalPath) {
+ assertThat(toDays(task.getLengthMilliseconds()), anyOf(equalTo(4),
+ equalTo(3)));
+ }
+ }
+
+ @Test
+ public void pairOfTasksEndEndFirstOfThemWithOneSubtask2() {
+ givenPairOfTasksEndEndFirstOfThemWithOneSubtask(2, 3, 6);
+ List criticalPath = new CriticalPathCalculator()
+ .calculateCriticalPath(diagramGraphExample);
+
+ assertThat(criticalPath.size(), equalTo(1));
+ assertThat(toDays(criticalPath.get(0).getLengthMilliseconds()),
+ equalTo(6));
+ }
+
+ @Test
+ public void twoTasksWithSubtasksRelatedWithEndEnd() {
+ givenTwoTasksWithSubtasksRelatedWithEndEnd(5, 3, 4, 2);
+ List criticalPath = new CriticalPathCalculator()
+ .calculateCriticalPath(diagramGraphExample);
+
+ assertThat(criticalPath.size(), equalTo(3));
+ for (ITaskFundamentalProperties task : criticalPath) {
+ assertThat(toDays(task.getLengthMilliseconds()), anyOf(equalTo(5),
+ equalTo(3), equalTo(2)));
+ }
+ }
+
+ @Test
+ public void twoTasksWithSubtasksRelatedWithEndEnd2() {
+ givenTwoTasksWithSubtasksRelatedWithEndEnd(5, 2, 4, 6);
+ List criticalPath = new CriticalPathCalculator()
+ .calculateCriticalPath(diagramGraphExample);
+
+ assertThat(criticalPath.size(), equalTo(2));
+ for (ITaskFundamentalProperties task : criticalPath) {
+ assertThat(toDays(task.getLengthMilliseconds()), anyOf(equalTo(4),
+ equalTo(6)));
+ }
+ }
+
+ @Test
+ public void exampleEndEnd() {
+ givenExampleEndEnd(5, 4, 2, 3);
+ List criticalPath = new CriticalPathCalculator()
+ .calculateCriticalPath(diagramGraphExample);
+
+ assertThat(criticalPath.size(), equalTo(2));
+ for (ITaskFundamentalProperties task : criticalPath) {
+ assertThat(toDays(task.getLengthMilliseconds()), anyOf(equalTo(5),
+ equalTo(4)));
+ }
+ }
+
+ @Test
+ public void exampleEndEnd2() {
+ givenExampleEndEnd(5, 2, 4, 3);
+ List criticalPath = new CriticalPathCalculator()
+ .calculateCriticalPath(diagramGraphExample);
+
+ assertThat(criticalPath.size(), equalTo(3));
+ for (ITaskFundamentalProperties task : criticalPath) {
+ assertThat(toDays(task.getLengthMilliseconds()), anyOf(equalTo(5),
+ equalTo(4), equalTo(3)));
+ }
+ }
+
+ @Test
+ public void exampleEndEnd3() {
+ givenExampleEndEnd(2, 4, 3, 10);
+ List criticalPath = new CriticalPathCalculator()
+ .calculateCriticalPath(diagramGraphExample);
+
+ assertThat(criticalPath.size(), equalTo(1));
+ assertThat(toDays(criticalPath.get(0).getLengthMilliseconds()),
+ equalTo(10));
+ }
+
}
\ No newline at end of file