def test_cond_next2(): # Get position: text = ",ab" nested = u.nest(text) assert u.cond_next(text, ",", nested, nested[0]) == 0 text = "a,b" nested = u.nest(text) assert u.cond_next(text, ",", nested, nested[0]) == 1
def test_nest(): np.testing.assert_array_equal(u.nest(""), np.zeros(0, dtype=int)) np.testing.assert_array_equal(u.nest("abc"), np.array([0, 0, 0])) np.testing.assert_array_equal(u.nest("\\n"), np.array([0, 0])) np.testing.assert_array_equal(u.nest("{a}"), np.array([0, 1, 1])) np.testing.assert_array_equal( u.nest("{{P\\'erez}, F. and {Granger}, B.~E.},"), np.array([ 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0 ]))
def test_cond_next3(): # Protected: text = "{a,b}" nested = u.nest(text) assert u.cond_next(text, ",", nested, nested[0]) == 4 text = "{a,b},c" nested = u.nest(text) assert u.cond_next(text, ",", nested, nested[0]) == 5 text = "{a and b} and c" nested = u.nest(text) assert u.cond_next(text, " and ", nested, nested[0]) == 9
def test_cond_next1(): # Empty string: text = "" nested = u.nest(text) assert u.cond_next(text, ",", nested, nested[0:1]) == 0 # Pattern not found in text, return last index: text = "ab" nested = u.nest(text) assert u.cond_next(text, ",", nested, nested[0]) == 1 text = "abcd" nested = u.nest(text) assert u.cond_next(text, ",", nested, nested[0]) == 3