class TestGetOpenNeighborhoods(TestFiniteTopology): """ Contains unit tests for the method that gets the first elements """ @given(topologies()) def test_get_open_neighborhood_of_point( self, topology: FiniteTopology ) -> None: """ :param topology: The topology for which open neighborhoods are to be obtained """ assume(frozenset(topology.elements) != frozenset()) first_point = next(iter(topology.elements)) open_neighborhoods = topology.get_open_neighborhoods(first_point) self.assertIsNotNone(open_neighborhoods) self.assertGreater(len(open_neighborhoods), 0) @given(topologies()) def test_closed_sets(self, topology: FiniteTopology[int]) -> None: """ Test that the complement of the closed sets of the topology are open sets :param topology: The topology for which closed sets are to be tested """ for closed_set in topology.closed_sets: self.assertIn( topology.elements.difference(closed_set), topology.open_sets )
class TestCustomTopologyGenerator(TestCustomTopology): """ Tests that the topology generator makes random topologies """ @given(topologies()) def test_generator(self, topol: Topology) -> None: self.assertIsInstance(topol, Topology)
class TestConstructor(TestRelativeTopology): """ Tests the constructor """ @given(topologies()) def test_valid_subset(self, topology: Topology): """ Tests that an isolated topology containing just the first element of a larger topology is a valid relative topology :param topology: The topology for which a relative topology is to be constructed :return: """ assume(len(list(topology.elements)) >= 2) first_element = next(iter(topology.elements)) subset = frozenset({first_element}) relative_topology = RelativeTopology(subset, topology) self.assertIn(first_element, relative_topology.elements) def test_invalid_subset(self) -> None: """ Tests that attempting to make an invalid relative topology throws an error """ with self.assertRaises(ValueError): RelativeTopology(frozenset({'item 3'}), self.custom_topology)
class TestProduct(TestFiniteTopology): """ Tests that multiplying two finite topologies together produces a product topology """ @given(topologies(), topologies()) def test_multiplication_two_topologies( self, first: FiniteTopology[int], second: FiniteTopology[int] ) -> None: """ Take two topologies and multiply them together. Check that the elements of the product topology are the products of the two separate topologies. :param first: The first topology to multiply :param second: The second topology to multiply """ product_topology = first * second self.assertEqual( set(product(first.elements, second.elements)), product_topology.elements )
class TestCustomBasis(unittest.TestCase): """ Contains unit tests for the basis """ @given(topologies()) def test_topology(self, topology: Topology) -> None: """ :param topology: The topology to test :return: """ basis = CustomBasis(topology.open_sets, topology) self.assertEqual(basis.topology, topology)
class TestComplement(TestFiniteTopology): """ Contains unit tests for the complement function """ @given(topologies()) def test_complement(self, topology: FiniteTopology[int]) -> None: """ The complement of the complement of a set should be the same set :param topology: The topology on which the complement is to be tested """ for open_set in topology.open_sets: self.assertEqual( open_set, topology.complement(topology.complement(open_set)) )