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