def test_good_case_2(self): s_a = r''' 0 1 1 0 1 2 3 0 2 3 4 0 3 4 -1 0 4 ''' fsa = k2host.str_to_fsa(s_a) rand_path = k2host.RandPath(fsa, False) array_size = k2host.IntArray2Size() rand_path.get_sizes(array_size) path = k2host.Fsa.create_fsa_with_size(array_size) arc_map = k2host.IntArray1.create_array_with_size(array_size.size2) status = rand_path.get_output(path, arc_map) self.assertTrue(status) self.assertFalse(k2host.is_empty(path)) self.assertFalse(arc_map.empty()) expected_arc_indexes = torch.IntTensor([0, 1, 2, 3, 4, 4]) expected_arcs = torch.IntTensor([[0, 1, 1, 0], [1, 2, 3, 0], [2, 3, 4, 0], [3, 4, -1, 0]]) expected_arc_map = torch.IntTensor([0, 1, 2, 3]) self.assertTrue(torch.equal(path.indexes, expected_arc_indexes)) self.assertTrue(torch.equal(path.data, expected_arcs)) self.assertTrue(torch.equal(arc_map.data, expected_arc_map))
def test_bad_case_1(self): # empty fsa array_size = k2host.IntArray2Size(0, 0) fsa = k2host.Fsa.create_fsa_with_size(array_size) rand_path = k2host.RandPath(fsa, False) array_size = k2host.IntArray2Size() rand_path.get_sizes(array_size) path = k2host.Fsa.create_fsa_with_size(array_size) arc_map = k2host.IntArray1.create_array_with_size(array_size.size2) status = rand_path.get_output(path, arc_map) self.assertFalse(status) self.assertTrue(k2host.is_empty(path)) self.assertTrue(arc_map.empty())
def test_bad_case_2(self): # non-connected fsa s_a = r''' 0 1 1 0 0 2 2 0 1 3 4 0 4 ''' fsa = k2host.str_to_fsa(s_a) rand_path = k2host.RandPath(fsa, False) array_size = k2host.IntArray2Size() rand_path.get_sizes(array_size) path = k2host.Fsa.create_fsa_with_size(array_size) arc_map = k2host.IntArray1.create_array_with_size(array_size.size2) status = rand_path.get_output(path, arc_map) self.assertFalse(status) self.assertTrue(k2host.is_empty(path)) self.assertTrue(arc_map.empty())
def test_good_case_1(self): s_a = r''' 0 1 1 0 0 2 2 0 1 2 3 0 2 3 4 0 2 4 5 0 3 4 7 0 4 5 9 0 5 ''' fsa = k2host.str_to_fsa(s_a) rand_path = k2host.RandPath(fsa, False) array_size = k2host.IntArray2Size() rand_path.get_sizes(array_size) path = k2host.Fsa.create_fsa_with_size(array_size) status = rand_path.get_output(path) self.assertTrue(status) self.assertFalse(k2host.is_empty(path))
def test_eps_arc_1(self): s_a = r''' 0 1 1 0 0 2 0 0 1 2 3 0 2 3 0 0 2 4 5 0 3 4 7 0 4 5 9 0 5 ''' fsa = k2host.str_to_fsa(s_a) rand_path = k2host.RandPath(fsa, True) array_size = k2host.IntArray2Size() rand_path.get_sizes(array_size) path = k2host.Fsa.create_fsa_with_size(array_size) arc_map = k2host.IntArray1.create_array_with_size(array_size.size2) status = rand_path.get_output(path, arc_map) self.assertTrue(status) self.assertFalse(k2host.is_empty(path)) self.assertFalse(arc_map.empty())