@@ -1484,6 +1484,25 @@ def test_tables_sequence_length_round_trip(self):
14841484 new_ts = tables .tree_sequence ()
14851485 self .assertEqual (new_ts .sequence_length , sequence_length )
14861486
1487+ def test_migrations (self ):
1488+ ts = msprime .simulate (
1489+ population_configurations = [
1490+ msprime .PopulationConfiguration (10 ),
1491+ msprime .PopulationConfiguration (10 )],
1492+ migration_matrix = [[0 , 1 ], [1 , 0 ]],
1493+ random_seed = 2 ,
1494+ record_migrations = True )
1495+ self .assertGreater (ts .num_migrations , 0 )
1496+ migrations = list (ts .migrations ())
1497+ self .assertEqual (len (migrations ), ts .num_migrations )
1498+ for migration in migrations :
1499+ self .assertIn (migration .source , [0 , 1 ])
1500+ self .assertIn (migration .dest , [0 , 1 ])
1501+ self .assertGreater (migration .time , 0 )
1502+ self .assertEqual (migration .left , 0 )
1503+ self .assertEqual (migration .right , 1 )
1504+ self .assertTrue (0 <= migration .node < ts .num_nodes )
1505+
14871506
14881507class TestFileUuid (HighLevelTestCase ):
14891508 """
@@ -2045,3 +2064,95 @@ def test_nonbinary(self):
20452064 self .assertTrue (found )
20462065 for _ in range (self .num_random_permutations ):
20472066 self .verify_random_permutation (ts )
2067+
2068+
2069+ class SimpleContainersMixin (object ):
2070+ """
2071+ Tests for the SimpleContainer classes.
2072+ """
2073+ def test_equality (self ):
2074+ c1 , c2 = self .get_instances (2 )
2075+ self .assertTrue (c1 == c1 )
2076+ self .assertFalse (c1 == c2 )
2077+ self .assertFalse (c1 != c1 )
2078+ self .assertTrue (c1 != c2 )
2079+ c3 , = self .get_instances (1 )
2080+ self .assertTrue (c1 == c3 )
2081+ self .assertFalse (c1 != c3 )
2082+
2083+ def test_repr (self ):
2084+ c , = self .get_instances (1 )
2085+ self .assertGreater (len (repr (c )), 0 )
2086+
2087+
2088+ class TestIndividualContainer (unittest .TestCase , SimpleContainersMixin ):
2089+ def get_instances (self , n ):
2090+ return [
2091+ tskit .Individual (id_ = j , flags = j , location = [j ], nodes = [j ], metadata = b"x" * j )
2092+ for j in range (n )]
2093+
2094+
2095+ class TestNodeContainer (unittest .TestCase , SimpleContainersMixin ):
2096+ def get_instances (self , n ):
2097+ return [
2098+ tskit .Node (
2099+ id_ = j , flags = j , time = j , population = j , individual = j , metadata = b"x" * j )
2100+ for j in range (n )]
2101+
2102+
2103+ class TestEdgeContainer (unittest .TestCase , SimpleContainersMixin ):
2104+ def get_instances (self , n ):
2105+ return [
2106+ tskit .Edge (left = j , right = j , parent = j , child = j ) for j in range (n )]
2107+
2108+
2109+ class TestSiteContainer (unittest .TestCase , SimpleContainersMixin ):
2110+ def get_instances (self , n ):
2111+ return [
2112+ tskit .Site (
2113+ id_ = j , position = j , ancestral_state = "A" * j ,
2114+ mutations = TestMutationContainer ().get_instances (j ),
2115+ metadata = b"x" * j )
2116+ for j in range (n )]
2117+
2118+
2119+ class TestMutationContainer (unittest .TestCase , SimpleContainersMixin ):
2120+ def get_instances (self , n ):
2121+ return [
2122+ tskit .Mutation (
2123+ id_ = j , site = j , node = j , derived_state = "A" * j , parent = j ,
2124+ metadata = b"x" * j )
2125+ for j in range (n )]
2126+
2127+
2128+ class TestMigrationContainer (unittest .TestCase , SimpleContainersMixin ):
2129+ def get_instances (self , n ):
2130+ return [
2131+ tskit .Migration (left = j , right = j , node = j , source = j , dest = j , time = j )
2132+ for j in range (n )]
2133+
2134+
2135+ class TestPopulationContainer (unittest .TestCase , SimpleContainersMixin ):
2136+ def get_instances (self , n ):
2137+ return [tskit .Population (id_ = j , metadata = "x" * j ) for j in range (n )]
2138+
2139+
2140+ class TestProvenanceContainer (unittest .TestCase , SimpleContainersMixin ):
2141+ def get_instances (self , n ):
2142+ return [
2143+ tskit .Provenance (id_ = j , timestamp = "x" * j , record = "y" * j ) for j in range (n )]
2144+
2145+
2146+ class TestEdgesetContainer (unittest .TestCase , SimpleContainersMixin ):
2147+ def get_instances (self , n ):
2148+ return [
2149+ tskit .Edgeset (left = j , right = j , parent = j , children = j ) for j in range (n )]
2150+
2151+
2152+ class TestVariantContainer (unittest .TestCase , SimpleContainersMixin ):
2153+ def get_instances (self , n ):
2154+ return [
2155+ tskit .Variant (
2156+ site = TestSiteContainer ().get_instances (1 )[0 ],
2157+ alleles = ["A" * j , "T" ], genotypes = np .zeros (j , dtype = np .int8 ))
2158+ for j in range (n )]
0 commit comments