Class ReplicatingGraphTest

java.lang.Object
edu.cmu.tetrad.graph.ReplicatingGraphTest

public class ReplicatingGraphTest extends Object
Tests for ReplicatingGraph with LagReplicationPolicy. Node naming convention: "X" = X at lag 0, "X:1" = X at lag 1, "X:2" = X at lag 2, etc. Key invariant: any mutation on one lag-slice (add, remove, orient) should be automatically mirrored to all other lag-slices that have the same base-variable pair with the same lag shift.
  • Constructor Details

    • ReplicatingGraphTest

      public ReplicatingGraphTest()
      Default constructor for the ReplicatingGraphTest class. Initializes the test class and its environment. This constructor is typically used to set up the test class before executing test cases.
  • Method Details

    • setUp

      public void setUp()
      Sets up the test environment by initializing the graph nodes and creating a new instance of the ReplicatingGraph class with a predefined list of nodes and a lag replication policy. This method is executed before each test case to ensure a clean and consistent starting state. The initialized nodes include: - Three lagged slices for variable X: x0, x1, x2. - Three lagged slices for variable Y: y0, y1, y2. The ReplicatingGraph instance g incorporates these nodes to enable operations and tests that rely on replication across lagged slices.
    • addContemporaneousEdge_mirrorsToAllLags

      public void addContemporaneousEdge_mirrorsToAllLags()
      Adding X:0 -- Y:0 (shift 0) should mirror to X:1 -- Y:1 and X:2 -- Y:2.
    • addContemporaneousEdgeAtLag1_mirrorsToOtherLags

      public void addContemporaneousEdgeAtLag1_mirrorsToOtherLags()
      Adding X:1 -- Y:1 (shift 0 at lag 1) should also mirror to lag 0 and lag 2.
    • addCrossLagEdge_mirrorsWhereNodesExist

      public void addCrossLagEdge_mirrorsWhereNodesExist()
      Adding X:1 --> Y:0 (shift -1, i.e. X at past lag drives Y now) should mirror to X:2 --> Y:1. There is no X:3 so no further mirror.
    • removeEdge_removesAllMirrors

      public void removeEdge_removesAllMirrors()
      Removing one slice of a mirrored contemporaneous edge should remove all slices.
    • removeCrossLagEdge_removesAllMirrors

      public void removeCrossLagEdge_removesAllMirrors()
      Removing a cross-lag edge should remove its mirror too.
    • addEdge_doesNotCreateSpuriousSameVariableEdges

      public void addEdge_doesNotCreateSpuriousSameVariableEdges()
      Adding X:0 -- Y:0 must not accidentally create X:0 -- X:1 or Y:0 -- Y:1, i.e. same-variable cross-lag edges.
    • edgeCount_contemporaneous_exactlyThree

      public void edgeCount_contemporaneous_exactlyThree()
      With 3 lag-slices and shift=0, one addUndirectedEdge call should produce exactly 3 edges total (one per slice).
    • edgeCount_crossLag_exactlyTwo

      public void edgeCount_crossLag_exactlyTwo()
      With 3 lags, a cross-lag edge (shift=-1) starting at lag 1 can mirror to lag 2 only → 2 edges total.
    • setEndpoint_mirrorsOrientationToAllSlices

      public void setEndpoint_mirrorsOrientationToAllSlices()
      Orienting one slice of a contemporaneous undirected edge should orient all slices the same way.
    • addEdge_noInfiniteRecursion

      public void addEdge_noInfiniteRecursion()
      Adding many edges should not cause a StackOverflowError. The IN_REPLICATION guard must prevent recursive re-entry.
    • copyConstructor_preservesEdgesExactly

      public void copyConstructor_preservesEdgesExactly()
      The copy constructor ReplicatingGraph(ReplicatingGraph) should produce an identical graph without doubling up edges.
    • noLagConvention_noMirroringNoException

      public void noLagConvention_noMirroringNoException()
      Nodes whose names don't follow the "X" / "X:N" convention should be treated as unrelated singletons — no mirroring, no exception.
    • factoryUtil_replicatingFlagTrue_returnsReplicatingGraph

      public void factoryUtil_replicatingFlagTrue_returnsReplicatingGraph()
      GraphFactoryUtil.newGraph(nodes, true) should return a ReplicatingGraph.
    • factoryUtil_replicatingFlagFalse_returnsEdgeListGraph

      public void factoryUtil_replicatingFlagFalse_returnsEdgeListGraph()
      GraphFactoryUtil.newGraph(nodes, false) should return a plain EdgeListGraph.
    • completeGraph_allNodesAdjacentAndTypePreserved

      public void completeGraph_allNodesAdjacentAndTypePreserved()
      Three variables (X, Y, Z) each replicated across three lags (0, 1, 2). After GraphUtils.completeGraph(), every pair of nodes should be adjacent and the graph should still be a ReplicatingGraph.