Class PagCacheTest
java.lang.Object
edu.cmu.tetrad.util.PagCacheTest
Unit tests for PagCache:
1) Repeated calls on same source return the SAME PAG object (identity preserved).
2) If a caller mutates the returned PAG, a subsequent getPag() repairs it IN PLACE (identity unchanged).
3) If the SOURCE graph changes structurally, getPag() rebuilds and returns a DIFFERENT PAG instance,
and then preserves that new identity across further calls.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidVerifies that external mutations of a PAG object retrieved from the cache are repaired directly within the same object instance (in-place), ensuring that the object identity is preserved.voidVerifies that thePagCacheconsistently returns the same PAG object for repeated calls with the same source graph as input.voidVerifies the behavior of thePagCachewhen the source graph (DAG) is modified after a PAG object has been retrieved from the cache.
-
Constructor Details
-
PagCacheTest
public PagCacheTest()Constructs a new instance of the PagCacheTest class. This constructor sets up the initial state for the test suite related to validating the behavior and functionality of the PagCache within its caching and repair mechanisms for PAGs derived from input DAGs.
-
-
Method Details
-
identityPreservedOnRepeatedCalls
public void identityPreservedOnRepeatedCalls()Verifies that thePagCacheconsistently returns the same PAG object for repeated calls with the same source graph as input. This test ensures that the object identity of the PAG is preserved when retrieving it multiple times from the cache for the same input DAG. The method validates the following: 1. The identity of the returned PAG object remains unchanged across successive calls toPagCache.getPag(Graph)for the same DAG instance. 2. The structure of the returned PAG matches the expected canonical representation generated from the reference PAG for the input DAG. Assertions: - Object identity of the PAG is preserved across calls. - PAG structure matches the deterministic encoded representation of the DAG's corresponding PAG. -
externalMutationIsRepairedInPlace
public void externalMutationIsRepairedInPlace()Verifies that external mutations of a PAG object retrieved from the cache are repaired directly within the same object instance (in-place), ensuring that the object identity is preserved. This test simulates a scenario where a caller modifies the endpoints of a PAG's edges after retrieving it from thePagCache. This induces a structural change to the PAG. The test then requests the PAG for the same DAG again from the cache and validates that: 1. The cache detects the mutation and repairs the PAG in-place. 2. The repaired PAG matches the expected structure derived from the reference. Validation includes: - Asserting that the PAG object's identity remains unchanged after repair. - Asserting that the structure of the repaired PAG matches the deterministic "canonical" representation of the DAG's PAG. -
sourceMutationForcesRebuildAndNewIdentity
public void sourceMutationForcesRebuildAndNewIdentity()Verifies the behavior of thePagCachewhen the source graph (DAG) is modified after a PAG object has been retrieved from the cache. This test ensures that structural mutations in the source graph force the cache to rebuild the associated PAG and return a new instance with updated contents. The test performs the following actions: 1. Constructs an initial DAG and retrieves its corresponding PAG from the cache. 2. Records the canonical structure of the initial PAG. 3. Mutates the source DAG by adding a new edge. 4. Retrieves the PAG from the cache again and confirms that: - The returned PAG is a new object (different identity from the initial PAG). - The new PAG accurately reflects the structural changes made to the source DAG. 5. Verifies that subsequent calls for the same mutated source DAG return the same PAG object, ensuring the new identity is stable. 6. Confirms that the structure of the returned PAG differs from the original canonical representation, indicating the change in the source DAG is reflected in the cache. Key Assertions: - Mutating the source graph causes the cached PAG entry to be replaced with a new instance. - Stable object identity is maintained for repeated calls with the updated source graph. - The structure of the returned PAG accurately reflects the modifications in the source DAG.
-