Best JavaScript code snippet using wpt
test_builtin.py
Source:test_builtin.py
...6from prolog.interpreter import error7from prolog.interpreter.test.tool import collect_all, assert_false, assert_true8from prolog.interpreter.test.tool import prolog_raises9def test_or():10 assert_false("fail;fail.")11 e = get_engine("""12 f(X, Y) :-13 ( fail14 ; X \== Y15 ).16 """)17 assert_false("f(X,X).", e)18def test_fail():19 e = get_engine("""20 g(a).21 f(X) :- g(X), fail.22 f(a).23 """)24 heaps = collect_all(e, "f(X).")25 assert len(heaps) == 126def test_not():27 assert_true("not(fail).")28 assert_false("not(true).")29 e = get_engine("""30 g(a, a).31 g(b, a).32 g(b, b).33 m(o, a).34 m(o, b).35 m(o, c).36 same(X, X).37 sibling(X, Y) :- m(Z, X), m(Z, Y), \\+same(X, Y).38 """)39 assert_true("not(g(b, c)).", e)40 assert_false("not(g(a, a)).", e)41 assert_true("\\+(g(b, c)).", e)42 assert_false("\\+(g(a, a)).", e)43 heaps = collect_all(e, "sibling(a, X).")44 assert len(heaps) == 245def test_and():46 assert_false("fail, X.")47 prolog_raises("type_error(callable, 1)", "(fail, 1)")48def test_nonvar():49 e = get_engine("""50 g(X) :- nonvar(X).51 g(x, X) :- nonvar(x), nonvar(X).52 f(X, Y) :- nonvar(X), nonvar(Y).53 """)54 assert_true("g(a).", e)55 assert_false("g(X).", e)56 assert_true("g(x).", e)57 assert_true("g(x, a).", e)58 assert_true("g(X, X).", e)59 assert_false("f(X, X).", e)60def test_consult():61 p = py.test.ensuretemp("prolog")62 f = p.join("test.pl")63 f.write("g(a, a). g(a, b).")64 e = get_engine("g(c, c).")65 assert_true("g(c, c).", e)66 assert_true("consult('%s')." % (f, ), e)67 assert_true("g(c, c).", e)68 assert_true("g(a, a).", e)69 assert_true("g(a, b).", e)70 prolog_raises("_", "consult('/hopefully/does/not/exist')")71def test_assert_retract():72 e = get_engine("g(b, b).")73 assert_true("g(B, B).", e)74 assert_true("assert(g(c, d)).", e)75 assert_true("assert(g(a, b)).", e)76 assert_true("assert(g(a, b)).", e) # assert the same rule multiple times77 assert_true("g(B, B).", e)78 assert_true("g(a, b).", e)79 assert_true("g(c, d).", e)80 assert_true("retract(g(B, B)).", e)81 assert_false("g(B, B).", e)82 assert_true("retract(g(a, b)).", e)83 assert_true("g(a, b).", e)84 assert_true("retract(g(a, b)).", e)85 assert_false("retract(g(a, b)).", e)86 assert_false("g(a, b).", e)87 assert_true("g(c, d).", e)88 e = get_engine("""89 g(b, b).90 f(X) :- g(X, b).91 f(a).92 """)93 assert_true("f(b).", e)94 assert_true("f(a).", e)95 assert_true("retract(f(X) :- g(X, Y)), Y == b.", e)96 assert_false("f(b).", e)97 assert_true("f(a).", e)98 prolog_raises("permission_error(X, Y, Z)", "retract(atom(X))")99def test_assert_at_right_end():100 e = get_engine("g(b, b). f(b, b). h(b, b).")101 assert_true("assert(g(a, a)).", e)102 assert_true("assertz(f(a, a)).", e)103 assert_true("A = a, asserta(h(A, A)).", e)104 f = assert_true("g(B, B).", e)105 assert f['B'].name()== "b"106 f = assert_true("f(B, B).", e)107 assert f['B'].name()== "b"108 assert_false("h(c, c).", e)109 f = assert_true("h(B, B).", e)110 assert f['B'].name()== "a"111def test_assert_logical_update_view():112 e = get_engine("""113 g(a).114 g(c) :- assertz(g(d)).115 g(b).116 """)117 heaps = collect_all(e, "g(X).")118 assert len(heaps) == 3119 e = get_engine("""120 p :- assertz(p), fail.121 p :- fail.122 """)123 assert_false("p.", e)124 e = get_engine("""125 q :- fail.126 q :- assertz(q), fail.127 """)128 assert_false("q.", e)129def test_assert_retract_colon():130 e = get_engine("""131 :(1, 2, 3).132 :(a).133 """)134 assert_true(":(1, 2, 3), :(a).", e)135 assert_true("assert(:(a, b, c, d)).", e)136 assert_true(":(a, b, c, d).", e)137 assert_true("retract(:(a, b, c, d)).", e)138 prolog_raises("existence_error(_, _)", ":(a, b, c, d)", e)139def test_abolish_colon():140 e = get_engine("""141 :(a).142 :(1, 2, 3).143 """)144 assert_true("abolish(:/1).", e)145 prolog_raises("existence_error(_, _)", ":(a)", e)146 assert_true(":(1, 2, 3).", e)147 assert_true("abolish(:/3).", e)148 prolog_raises("existence_error(_, _)", ":(1, 2, 3)", e)149def test_retract_logical_update_view():150 e = get_engine("""151 p :- retract(p :- true), fail.152 p :- true.153 """)154 assert_true("p.", e)155 assert_false("p.", e)156def test_abolish():157 e = get_engine("g(b, b). g(c, c). g(a). f(b, b). h(b, b).")158 assert_true("abolish(g/2).", e)159 assert_true("g(a).", e)160 prolog_raises("existence_error(X, Y)", "g(A, B)", e)161 prolog_raises("type_error(predicate_indicator, a)", "abolish(a)", e)162def test_unify():163 assert_true("g(b, B) = g(b, b).")164 assert_true("X = Y.")165 assert_true("X = f(X).")166 assert_false("g(b, B) \\= g(b, b).")167 assert_false("X \\= Y.")168 assert_false("X \\= f(X).")169 assert_true("x \\= y.")170 assert_true("f(X, b) \\= f(a, c), X = c.")171 assert_true("unify_with_occurs_check(X, Y).")172 assert_true("unify_with_occurs_check(X, X).")173 assert_false("unify_with_occurs_check(X, f(X)).")174 assert_false("unify_with_occurs_check(X, f(g(h(a, b, c, d(X, e), e)))).")175 assert_false("unify_with_occurs_check(g(X), X).")176 assert_false("X = Y, unify_with_occurs_check(X, f(d(Y), Y)).")177def test_call():178 e = get_engine("g(b, b).")179 assert_true("call(g(X, X)).", e)180 assert_true("X =.. [g, b, b], call(X).", e)181 e = get_engine("""182 g(X) :- call(f(X)).183 g(a).184 g(b).185 f(X) :- !, h(X).186 f(a).187 f(b).188 h(X) :- fail.189 withcut(X) :- call(!), fail.190 withcut(a).191 """)192 heaps = collect_all(e, "g(X).")193 assert len(heaps) == 2194 assert_true("withcut(a).", e)195 assert_true("call((!, true)).")196def test_cut():197 e = get_engine("""198 f(0).199 f(X) :- Y is X - 1, !, f(Y).200 f(X) :- Y is X - 2, !, f(Y).201 """)202 assert_true("f(20).", e)203def test_cut_with_throw():204 e = get_engine("""205 raise_if_var(X) :-206 var(X), !, throw(unbound).207 raise_if_var(X) :- X = a.208 c(X, Y) :- catch((raise_if_var(X), Y = b), E, Y = a).209 """)210 assert_true("c(_, Y), Y == a.", e)211def test_cut_with_throw_direct():212 e = get_engine("""213 c(X, Y) :- catch(((X = a; X = b), !, X = b, Y = b), E, Y = a); X = c.214 """)215 assert_true("c(X, Y), X == c.", e)216def test_call_cut():217 e = get_engine("""218 f(X) :- call(X).219 f(!).220 """)221 heaps = collect_all(e, "f(!).")222 assert len(heaps) == 2223 assert_true("call(((X = a; X = b), !, X = b)); X = c.")224 assert_false("(((X = a; X = b), !, X = b)); X = c.")225def test_bug_or_exposing_problem_of_cyclic_term_support():226 e = get_engine("""227 f(X) :- (X = 1; X = 2), X = 2.228 """)229 assert_true("f(X).", e)230def test_or_and_call_with_cut():231 e = get_engine("""232 f :- (!, fail); true.233 g :- (call(!), fail); true.234 """)235 assert_false("f.", e)236 assert_true("g.", e)237def test_or_with_cut():238 e = get_engine("""239 f(X) :- ((X = 1, !); X = 2), X = 2.240 g(X) :- ((X = 1, !); X = 2), X = 1.241 """)242 assert_false("f(X).", e)243 assert_true("g(X).", e)244def test_cut1():245 e = get_engine("""246 g(a).247 g(b).248 a(a).249 b(b).250 f(X) :- g(X),!,b(X).251 f(x).252 f(y).253 """)254 heaps = collect_all(e, "f(X).")255 assert len(heaps) == 0256 assert_true("!.")257def test_cut2():258 e = get_engine("""259 g(a).260 g(b).261 h(a, x).262 h(a, y).263 f(X, Y) :- g(X), !, !, !, !, !, h(X, Y).264 """)265 heaps = collect_all(e, "f(X, Y).")266 assert len(heaps) == 2267def test_cut3():268 e = get_engine("""269 member(H, [H | _]).270 member(H, [_ | T]) :- member(H, T).271 s(a, L) :- !, fail.272 s(b, L).273 s(X, L) :-274 member(Y, L),275 L = [_| S],276 s(Y, S).277 """)278 # import pdb; pdb.set_trace()279 assert_true("s(d, [a, b]).", e)280def test_rule_with_cut_calling_rule_with_cut():281 e = get_engine("""282 e(a).283 e(b).284 f(b) :- e(_), !.285 f(c).286 g(X) :- f(X), !.287 g(a).288 """)289 heaps = collect_all(e, "g(X).")290 assert len(heaps) == 1291def test_not_with_cut():292 assert_true("not((!, fail)).")293 assert_false("not(!).")294 e = get_engine("""295 p1 :- \\+ q1.296 q1 :- fail.297 q1 :- true.298 299 p2:- \\+ q2.300 q2 :- !, fail.301 q2 :- true.302 """)303 assert_false("p1.", e)304 assert_true("p2.", e)305def test_not_stops_cut():306 e = get_engine("""307 f(X) :- (X = a; X = b), not((!, fail)).308 """)309 assert_true("f(X), X = b.", e)310 assert_true("not(((X = 1; X = 2), !, X=2)).", e)311def test_two_cuts():312 e = get_engine("""313 f(>, X) :- X > 0, !.314 f(=, X) :- X = 0, !.315 f(<, _).316 """)317 assert_true("f(X, 1), X = '>'.", e)318 assert_true("f(X, 0), X = '='.", e)319 assert_true("f(X, -1), X = '<'.", e)320def test_listify():321 e = get_engine("""322 listify(_X, _X) :-323 (var(_X); atomic(_X)), !.324 listify(_Expr, [_Op|_LArgs]) :-325 functor(_Expr, _Op, N),326 listify_list(1, N, _Expr, _LArgs).327 listify_list(I, N, _, []) :- I>N, !.328 listify_list(I, N, _Expr, [_LA|_LArgs]) :- I=<N, !,329 arg(I, _Expr, _A),330 listify(_A, _LA),331 I1 is I+1,332 listify_list(I1, N, _Expr, _LArgs).333 """)334 assert_true("listify(f(X), Y), Y = [f, X].", e)335 assert_true("listify(f(X, g(1)), Y).", e)336 assert_true("listify(f(X, 1, g(1)), Y), Y = [f, X, 1, [g, 1]].", e)337def test_univ():338 assert_true("g(a, b, c) =.. [G, A, B, C].")339 assert_true("g(a, b, c) =.. [g, a, b, c].")340 assert_true("X =.. [g, a, b, c], X = g(a, b, c).")341 assert_true("L = [a|X], X = [], Z =.. L, Z == a.")342 assert_true("L = [X, 1, 2], X = a, Z =.. L, Z == a(1, 2).")343def test_arg():344 assert_true("arg(1, g(a, b, c), a).")345 assert_true("arg(2, g(a, b, c), b).")346 assert_true("arg(3, g(a, b, c), c).")347 assert_false("arg(3, g(a, b, c), d).")348 assert_false("arg(0, g(a, b, c), X).")349 assert_false("arg(10, g(a, b, c), X).")350 assert_true("arg(1, g(a, b, c), X), X = a.")351 assert_true("arg(2, f(a, b, c), X), X = b.")352 assert_true("arg(3, h(a, b, c), X), X = c.")353 e = get_engine("""354 f(1, a).355 f(2, b).356 f(3, c).357 """)358 heaps = collect_all(e, "arg(X, g(a, b, c), A), f(X, A).")359 assert len(heaps) == 3360 assert_true("arg(X, h(a, b, c), b), X = 2.")361 assert_true("arg(X, h(a, b, g(X, b)), g(3, B)), X = 3, B = b.")362 assert_false("arg(X, a, Y).")363 prolog_raises("_", "arg(X, 1, Y)")364def test_copy_term():365 assert_true("copy_term(X, Y), X = 1, Y = 2.")366 assert_true("copy_term(a, a).")367 assert_false("copy_term(f(X), g(X)).")368 assert_true("copy_term(f(X), f(a)), X = b.")369def test_type_checks():370 assert_true("integer(123).")371 assert_true("integer(1000000000000000000000000000000000000).")372 assert_true("integer(-1000000000000000000000000000000000000).")373 assert_false("integer(a).")374 assert_false("integer(X).")375 assert_true("float(123.12).")376 assert_false("float(a).")377 assert_false("float(12).")378 assert_true("number(123).")379 assert_true("number(1000000000000000000000000000000000000).")380 assert_true("number(-1000000000000000000000000000000000000).")381 assert_true("number(42.42).")382 assert_false("number(abc).")383 assert_false("integer(a).")384 assert_false("integer(X).")385 assert_true("var(X).")386 assert_false("X = a, var(X).")387 assert_true("compound(g(a)).")388 assert_false("compound(gxx).")389 assert_false("compound(123).")390 assert_false("compound([]).")391 assert_false("compound(X).")392 assert_true("atom(a).")393 assert_true("atom('asdf').")394 assert_false("atom(12).")395 assert_false("atom(X).")396 assert_true("atomic('asdf').")397 assert_true("atomic(12.5).")398 assert_false("atomic(f(1, 2, 3)).")399 assert_false("atomic(X).")400 assert_false("callable(X).")401 assert_false("callable(1).")402 assert_true("callable(asdf).")403 assert_true("callable(asdf(a, b, c, d, e, f)).")404 assert_true("ground(a).")405 assert_true("ground(t(a, b, f(a, b, g(a, b)))).")406 assert_false("ground(t(a, b, f(a, b, g(a, X)))).")407 assert_true("X = 13, ground(t(a, b, f(a, b, g(a, X)))).")408 assert_false("ground(X).")409def test_repeat():410 assert_true("repeat, true.")411 e = Engine()412 assert_false("repeat, !, fail.")413 # hard to test repeat differently414 e = get_engine('f :- repeat, !, fail.')415 assert_false('f.', e)416 assert_true('f; true.', e)417def test_exception_handling():418 assert_true("catch(f, E, true).")419 assert_true("catch(throw(error), E, true).")420 prolog_raises("_", "catch(true, E, fail), f")421 prolog_raises("_", "catch(throw(error(x)), error(failure), fail)")422 assert_true("catch(catch(throw(error), failure, fail), error, true).")423 assert_true("catch((X = y, throw(X)), E, E == y).")424def test_exception_forces_backtracking():425 assert_true("catch((X = 1, throw(f(X))), Y, (var(X), Y == f(1))), var(X).")426def test_between():427 assert_true("between(12, 15, 12).")428 assert_true("between(-5, 15, 0).")429 assert_false("between(12, 15, 6).")430 assert_false("between(12, 15, 16).")431 heaps = collect_all(Engine(), "between(1, 4, X).")432 assert len(heaps) == 4433 assert heaps[0]['X'].num == 1434 assert heaps[-1]['X'].num == 4435def test_is():436 assert_true("5 is 1 + 1 + 1 + 1 + 1.")437@py.test.mark.xfail438def test_parser_access():439 assert_true("current_op(200, xfx, **).")440 f = collect_all(Engine(), "current_op(200, Form, X).")441 assert len(f) == 2442 e = get_engine("""443 foo(a, b).444 """)445 assert_true("op(450, xfy, foo).", e)446 assert_true("a foo b.", e)447 assert_true("op(0, xfy, foo).", e)448 # XXX really a ParseError449 py.test.raises(Exception, assert_false, "a foo b.", e) 450 # change precedence of + for funny results :-)451 assert_true("14 is 2 + 3 * 4.", e)452 assert_true("op(350, xfy, +).", e)453 assert_true("20 is 2 + 3 * 4.", e)454 assert_true("op(500, xfy, +).", e)455def test_functor():456 assert_true("functor(f(a, b, c), f, 3).")457 assert_true("functor(f(a, b, c), X, Y), X=f, Y=3.")458 assert_true("functor(f, X, Y), X=f, Y=0.")459 assert_true("functor(1, X, Y), X=1, Y=0.")460 assert_true("functor(F, a, 0), F=a.")461 assert_true("functor(F, 12, 0), F=12.")462 assert_true("functor(F, 12.5, 0), F=12.5.")463 assert_true("functor(F, f, 4), F=f(1, 2, 3, 4).")464 assert_true("functor(F, g, 1), F=g(asdf).")465 assert_true("functor(F, g, 3), F=g(X, Y, 1), X = 12, Y = 34, ground(F).")466def test_compare():467 assert_true("X = Y, compare(R, f(X, Y, X, Y), f(X, X, Y, Y)), R == '='.")468 assert_true("X = f(a), Y = f(b), compare(R, Y, X), R == '>'.")469def test_atom_length():470 assert_true("atom_length('abc', 3).")471 assert_true("atom_length('\\\\', 1).")472 assert_true("atom_length('abc', X), X = 3.")473def test_atom_concat():474 assert_true("atom_concat(ab, cdef, abcdef).")475 assert_true("atom_concat(ab, cdef, X), X = abcdef.")476 assert_true("atom_concat(ab, X, abcdef), X = cdef.")477 assert_true("atom_concat(X, cdef, abcdef), X = ab.")478 assert_true("atom_concat(1, Y, '1def'), Y = def.")479 heaps = collect_all(480 Engine(),481 "atom_concat(X, Y, abcd), atom(X), atom(Y).")482 assert len(heaps) == 5483@py.test.mark.xfail484def test_sub_atom():485 assert_true("sub_atom(abc, B, L, A, bc), B=1, L=2, A=0.")486@py.test.mark.xfail487def test_sub_atom2():488 assert_false("sub_atom(abc, B, 1, A, bc).")489@py.test.mark.xfail490def test_sub_atom3():491 assert_true("sub_atom(abcabcabc, 3, 3, A, abc), A=3.")492@py.test.mark.xfail493def test_sub_atom4():494 assert_true("sub_atom(abcabcabc, B, L, 3, abc), B=3, L=3.")495@py.test.mark.xfail496def test_sub_atom_with_non_var_sub():497 assert_true("sub_atom(abcabc, Before, Length, After, a), Before=3, Length=1, After=2.")498 assert_false("sub_atom(abcabc, Before, Length, After, b), Before==3, Length==1, After==2.")499@py.test.mark.xfail500def test_sub_atom_with_var_after():501 assert_true("sub_atom(abcabd, 2, 1, After, Sub), After=3, Sub=c.")502 assert_true("sub_atom(abcabc, Before, Length, After, Sub), Before=1, Length=3, After=2, Sub=bca.")503 assert_false("sub_atom(abcabc, 1, 3, After, Sub), Sub=abc.")504@py.test.mark.xfail505def test_sub_atom_var_sub_and_non_var_after():506 assert_true("sub_atom(abcabd, 2, 1, 3, Sub), Sub=c.")507 assert_true("sub_atom(abcabc, Before, Length, 2, Sub), Before=1, Length=3, Sub=bca.")508 assert_false("sub_atom(abcabc, 1, 3, 2, Sub), Sub=abc.")509def test_findall():510 assert_true("findall(X, (X = a; X = b; X = c), L), L == [a, b, c].")511 assert_true("findall(X + Y, (X = 1; X = 2), [1+A, 2+B]), A \== B.")512 e = get_engine("""513 app([], X, X).514 app([H | T1], T2, [H | T3]) :-515 app(T1, T2, T3).516 """)517 assert_true("findall(X+Y, app(X, Y, [1, 2, 3]), L), L == [[]+[1, 2, 3], [1]+[2, 3], [1, 2]+[3], [1, 2, 3]+[]].", e)518def test_findall_and_exception_bug():519 prolog_raises("instantiation_error", "findall(1, 0 is X, _)")520def test_ifthenelse():521 assert_false("true -> fail.")522 assert_false("true -> fail ; true.")523 assert_true("fail -> fail ; true.")524 assert_true("fail -> true ; true.")525 assert_true("(true -> fail ; true) ; true.")526 e = get_engine("f(x). f(y). f(z).")527 assert_false("f(c) -> true.", e)528 assert_false("f(X) -> X \\= x; f(z).", e)529 assert_true("f(X) -> X == x; f(z).", e)530 assert_true("""531 L = [X, Y],532 (L = []533 ->534 true535 ;536 [Head|Tail] = L537 ).538 """)539def test_cut_in_ifthenelse():540 e = get_engine("""541 f(X) :- ! -> fail.542 f(0)....
test_coroutines.py
Source:test_coroutines.py
...12 X = 1.13 """,14 load_system=True)15def test_unifiable():16 assert_false("unifiable(a, b, _).", e)17 assert_true("unifiable(a, a, X), X == [].", e)18 assert_true("unifiable(X, X, L), L == [].", e)19 assert_true("unifiable(X, Y, L), L == [X-Y].", e)20 assert_true("unifiable(f(a), f(a), L), L == [].", e)21 assert_true("unifiable([A, B, C], T, X), X == [T-[A, B, C]].", e)22 assert_true("unifiable([A, B, C], [S|T], X), X == [T-[B, C], A-S].", e)23 assert_true("unifiable(f(a, b, T), X, L), L == [X-f(a, b, T)].", e)24 assert_true("unifiable(f(g(t(Z)), b, x(y(a))), f(g(Q), b, x(y(A))), L), L == [A-a, Q-t(Z)].", e)25 assert_true("unifiable([X1, X2, X3], [Y1, Y2, Y3], L), L == [X3-Y3, X2-Y2, X1-Y1].", e)26def test_freeze():27 assert_true("freeze(X, Y = 1), X = 1, Y == 1.", e)28 assert_false("freeze(X, true), X = 1, attvar(X).", e)29 assert_false("freeze(X, Y = 1), X = 1, fail; Y == 1.", e)30 assert_true("freeze(a, Y = 1), Y == 1.", e)31 prolog_raises("existence_error(_, _)", "freeze(a, a)", e)32 assert_true("freeze(X, Y = 1), freeze(X, Z = 2), X = a, Y == 1, Z == 2.", e)33 assert_true("freeze(X, f(a)), X = 1.", e)34 assert_true("freeze(X, user:f(a)), X = 1.", e)35 assert_true("freeze(X, m:g(q)), X = 1.", e)36 assert_false("freeze(X, Y = 1), freeze(X, Y = 2), X = a.", e)37 assert_true("freeze(X, Y = 1), freeze(X, Z = 2), X = a, Y == 1, Z == 2.", e)38 assert_true("freeze(X, Z1 = 1), freeze(Y, Z2 = 2), var(Z1), var(Z2), X = Y, var(Z1), var(Z2).", e)39 assert_true("freeze(X, Z1 = 1), freeze(Y, Z2 = 2), var(Z1), var(Z2), X = Y, var(Z1), var(Z2), X = 1, Z1 == 1, Z2 == 2.", e)40 assert_true("freeze(X, Z1 = 1), freeze(Y, Z2 = 2), var(Z1), var(Z2), X = Y, var(Z1), var(Z2), Y = 1, Z1 == 1, Z2 == 2.", e)41 assert_true("freeze(X, Z1 = 1), freeze(Y, Z2 = 2), var(Z1), var(Z2), Y = X, var(Z1), var(Z2), Y = 1, Z1 == 1, Z2 == 2.", e)42def test_frozen():43 assert_false("frozen(a, a).", e)44 assert_true("frozen(1, X), X == true.", e)45 assert_true("frozen(X, X), X == true.", e)46 assert_true("frozen(X, Y), Y == true, var(X).", e)47 assert_true("freeze(X, f(a)), frozen(X, user:f(a)).", e)48 assert_true("freeze(X, m:g(q)), frozen(X, R), R == m:g(q).", e)49 assert_true("freeze(X, true), frozen(X, user:true), freeze(X, fail), frozen(X, (user:true, user:fail)).", e)50 assert_true("freeze(X, true), X = a, frozen(X, R), R == true.", e)51def test_when_nonvar():52 assert_true("when(nonvar(X), Y = 1), X = a, Y == 1.", e)53 assert_true("when(nonvar(a), f(a)).", e)54 assert_true("when(nonvar(a), (X = 1, Y = 2)), X == 1, Y == 2.", e)55 assert_true("when(nonvar(a), z).", e)56 assert_true("when(nonvar(X), f(a)), X = 1.", e)57 assert_true("when(nonvar(X), A = 1), when(nonvar(Y), B = 2), X = Y, var(A), var(B), X = a, A == 1, B == 2.", e)58 assert_true("when(nonvar(X), A = 1), when(nonvar(Y), B = 2), Y = X, var(A), var(B), X = a, A == 1, B == 2.", e)59 assert_true("when(nonvar(X), A = 1), when(nonvar(Y), B = 2), X = Y, var(A), var(B), Y = a, A == 1, B == 2.", e)60 assert_true("when(nonvar(X), A = 1), when(nonvar(Y), B = 2), Y = X, var(A), var(B), Y = a, A == 1, B == 2.", e)61def test_when_ground():62 assert_true("when(ground(f(X, Y)), Z = 1), X = 1, var(Z), Y = a, Z == 1.", e)63 assert_true("when(ground(f(X, Y)), Z = 1), Y = 1, var(Z), X = a, Z == 1.", e)64 assert_false("when(ground(f(X, Y)), Z = 1), X = 1, Z == 1.", e)65 assert_true("when((ground(X), ground(Y)), Z = 1), X = a, var(Z), Y = b, Z == 1.", e)66 assert_true("when((ground(X), ground(Y)), Z = 1), Y = a, var(Z), X = b, Z == 1.", e)67 assert_true("when((ground(a), ground(Y)), Z = 1), var(Z), Y = a, Z == 1.", e)68 assert_true("when((ground(X), ground(a)), Z = 1), var(Z), X = a, Z == 1.", e)69 assert_true("when((ground(a), ground(a)), Z = 1), Z == 1.", e)70 assert_true("when((ground(X); ground(Y)), Z = 1), var(Z), Y = b, Z == 1.", e)71 assert_true("when((ground(X); ground(Y)), Z = 1), var(Z), X = b, Z == 1.", e)72 assert_true("when((ground(X); ground(Y)), Z = 1), var(Z), Y = b, Z == 1, X = a.", e)73 assert_true("when((ground(X); ground(Y)), test_once(Z)), var(Z), Y = b, Z == 1, X = a.", e)74 assert_true("when(ground(1), m:g(q)).", e)75 assert_true("when(ground(X), Y = 1), X = a, Y == 1.", e)76 assert_true("when(ground(X), Y = 1), when(ground(X), Z = 2), X = a, Y == 1, Z == 2.", e)77 assert_true("when(ground(X), Y), when(ground(A), Y = (B = 3)), A = a, X = q, Y == (3 = 3).", e)78 assert_true("when(ground(f(X, Y)), when(ground(X), Z = 1)), X = a, var(Z), Y = b, Z == 1.", e)79 assert_true("when(ground(f(X, Y)), when(ground(A), Z = 1)), X = a, var(Z), Y = b, var(Z), A = 1, Z == 1.", e)80 assert_true("when(ground(X), A = 1), when(ground(Y), B = 2), X = Y, var(A), var(B), X = a, A == 1, B == 2.", e)81 assert_true("when(ground(X), A = 1), when(ground(Y), B = 2), Y = X, var(A), var(B), X = a, A == 1, B == 2.", e)82 assert_true("when(ground(X), A = 1), when(ground(Y), B = 2), X = Y, var(A), var(B), Y = a, A == 1, B == 2.", e)83 assert_true("when(ground(X), A = 1), when(ground(Y), B = 2), Y = X, var(A), var(B), Y = a, A == 1, B == 2.", e)84def test_when_decidable():85 assert_true("when(?=(1, 1), X = a), X == a.", e)86 assert_true("when(?=(X, X), Z = a), Z == a.", e)87 assert_false("when(?=(X, Y), Z = a), Z == a.", e)88 assert_true("when(?=(f(X, Y), f(A, B)), Q = 1), X = a, A = a, var(Q), Y = b, B = b, Q == 1.", e)89 assert_true("when(?=(f(X, Y), f(A, B)), Q = 1), Y = a, B = a, var(Q), X = b, A = b, Q == 1.", e)90 assert_true("when(?=(f(X, Y), f(A, B)), Q = 1), Y = a, B = 1, Q == 1.", e)91 assert_true("when(?=(f(X, Y), f(A, B)), Q = 1), X = a, A = 1, Q == 1.", e)92 assert_true("when(?=(f(X, Y), f(A, B)), Q = 1), X = a, B = 1, var(Q).", e)93 assert_true("when(?=(X, Y), Z = 1), var(Z), X = Y, Z == 1.", e)94 assert_false("when(?=(X, Y), X \== Y), X = Y.", e)95 assert_false("when(?=(f(1), f(2)), nl), fail.", e)96 assert_false("when(?=(f(A, B), f(a, b)), test_once(Z)), var(Z), A = 1, B = 2, Z == a.", e)97 assert_true("when(?=(X, Y), Z = a), Y = a, X = b, Z == a.", e)98 assert_true("when(?=(X, Y), Z = a), X = a, Y = b, Z == a.", e)99 assert_true("when(?=(f(A, B), f(a, b)), test_once(Z)), var(Z), A = 1, B = 2, Z == 1.", e)100 assert_true("when(?=(f(X), f(X)), Z = a), Z == a.", e)101 assert_true("when(?=(f(X, Y), f(X, Y)), Z = a), Z == a.", e)102 assert_true("when(?=(f(X, Y), f(X, W)), Z = a), var(Z), Y = 1, var(Z), W = 1, Z == a.", e)103 assert_false("when(?=(f(X), f(Y)), Z = a), Z == a.", e)104 assert_false("when(?=(X, f(X)), Z = a), Z == a.", e)105 assert_true("when(?=([1, 2, 3], X), C = 1), X = [1|Y], var(C), Y = [2|Z], var(C), Z = [3], C == 1.", e)106 assert_true("when(?=([X, Y], [X, X]), Q = 1), when(?=(X, Z), R = 2), X = Z, R == 2, var(Q), Y = X, Q == 1.", e) 107def test_when_errors():108 prolog_raises("domain_error(_, _)", "when(var(X), f(a))", e)109 prolog_raises("domain_error(_, _)", "when((ground(1), (ground(1), var(1))), f(a))", e)110 prolog_raises("domain_error(_, _)", "when(((1; 2), (ground(1), nonvar(1))), f(a))", e)111 prolog_raises("instantiation_error", "when(X, X == 1)", e)112 prolog_raises("instantiation_error", "when(nonvar(a), X)", e)113 prolog_raises("instantiation_error", "when(ground(X), Y), when(ground(A), Y = (B = 3)), X = q, A = 1", e)114def test_hard_when():115 assert_true("findall(Z, (when(?=(X, Y), Z = a), X = a, Y = b), L), L == [a].", e)116 assert_true("when(nonvar(X), Y = 1), when(nonvar(A), G = 1), X = A, var(Y), var(G).", e)117 assert_true("when(nonvar(X), A = 1), when(nonvar(Y), B = 2), X = Y, Y = a, A == 1, B == 2.", e)118 assert_true("when(nonvar(X), assert(xyz(a))), when(nonvar(Y), assert(xyz(b))), X = Y, Y = a.", e)119 assert_true("findall(X, xyz(X), L), L == [b, a].", e)120 assert_true("abolish(xyz/1).", e)121def test_freeze_when_mix():122 assert_true("freeze(X, A = 1), when(nonvar(X), B = 2), var(A), var(B), X = a, A == 1, B == 2.", e)123 assert_true("freeze(X, A = 1), when(nonvar(Y), B = 2), X = Y, var(A), var(B), X = a, A == 1, B == 2.", e)124 assert_true("freeze(X, A = 1), when(nonvar(Y), B = 2), Y = X, var(A), var(B), X = a, A == 1, B == 2.", e)125 assert_true("when(nonvar(X), A = 1), freeze(Y, B = 2), X = Y, var(A), var(B), X = a, A == 1, B == 2.", e)126 assert_true("when(nonvar(X), A = 1), freeze(Y, B = 2), Y = X, var(A), var(B), X = a, A == 1, B == 2.", e)127 assert_true("freeze(X, A = 1), freeze(Y, B = 2), when(nonvar(Y), C = 3), X = Y, var(A), var(B), var(C), X = a, A == 1, B == 2, C == 3.", e)128 assert_true("freeze(X, A = 1), freeze(Y, B = 2), when(nonvar(Y), C = 3), Y = X, var(A), var(B), var(C), X = a, A == 1, B == 2, C == 3.", e)129 assert_true("when(nonvar(X), A = 1), freeze(Y, B = 2), when(nonvar(Y), C = 3), Y = X, var(A), var(B), var(C), X = a, A == 1, B == 2, C == 3.", e)130 assert_true("when(nonvar(X), A = 1), freeze(Y, B = 2), when(nonvar(Y), C = 3), Y = X, var(A), var(B), var(C), X = a, A == 1, B == 2, C == 3.", e)131def test_meta_predicate_with_when():132 e = get_engine("""133 :- use_module(m).134 """,135 m = """136 :- module(m, [f/2]).137 f(X, Y) :-138 when(nonvar(X), Y == X).139 """, 140 load_system=True)141 assert_true("module(m).", e)142 assert_true("f(X, a), X = a.", e)143 assert_false("f(X, a), X = b.", e)144 assert_true("module(user).", e)145 assert_true("f(X, a), X = a.", e)146 assert_false("f(X, a), X = b.", e)147 assert_true("m:f(X, a), X = a.", e)148 assert_false("m:f(X, a), X = b.", e)149def test_block():150 e = get_engine("""151 :- block f('?', '-', '?'), f('-', '-', '?').152 :- block g('?').153 :- block h('-', '-', '-', '?'), h('-', '-', '?', '?'), h('-', '?', '?', '?').154 f(A, B, C) :-155 C = 10.156 g(_) :-157 assert(gg(1)).158 h(A, B, C, D) :-159 D is A + B + C.160 """, load_system=True)161 assert_false("f(X, Y, Z), Z == 10.", e)162 assert_false("f(a, X, Z), Z == 10.", e)163 assert_true("f(a, b, Z), Z == 10.", e)164 assert_true("f(a, X, Z), \+ Z == 10, X = 5, Z == 10.", e)165 assert_true("f(A, B, Z), \+ Z == 10, A = a, \+ Z == 10, B = b, Z == 10.", e)166 assert_true("f(a, X, Z), (X = 1, fail; true), var(Z).", e)167 prolog_raises("existence_error(_, _)", "g(5), gg(1)", e)168 prolog_raises("existence_error(_, _)", "g(X), gg(1)", e)169 assert_true("h(A, B, C, D), var(D), C = 5, var(D), B = 5, var(D), A = 5, D == 15.", e)170 prolog_raises("instantiation_error", "h(5, B, C, D)", e)171 prolog_raises("instantiation_error", "h(5, 1, C, D)", e)172 assert_true("h(1, 2, 3, 6).", e)173 assert_true("h(A, B, C, D), var(D), B = 5, var(D), C = 5, var(D), A = 5, D == 15.", e)174def test_block_sort():175 e = get_engine("""176 sorted2([]).177 sorted2([H|T]) :- s2(T,H).178 :- block s2('-','?').179 s2([],_).180 s2([H|T],P) :- lt(P,H), s2(T,H).181 :- block lt('-','?'), lt('?','-').182 lt(X,Y) :- X<Y.183 pp([],[]).184 pp([H|T],[X|RT]) :-185 sel(X,[H|T],R), pp(R,RT).186 187 dosort(List, Ret) :-188 sorted2(Ret),189 pp(List, Ret).190 mem(X, [X|_]).191 mem(X, [_|T]) :-192 mem(X, T).193 rem(_, [], []).194 rem(X, [X|R], R).195 rem(X, [H|T], [H|R]) :-196 X \= H,197 rem(X, T, R).198 sel(X, List, R) :-199 mem(X, List),200 rem(X, List, R). 201 """, load_system=True)202 assert_true("dosort([5,4,3,2,1], X), X == [1,2,3,4,5].", e)203 assert_false("dosort([5,4,3,2,1], X), X == [1,3,2,4,5].", e)204def test_dif():205 assert_true("dif(1, 2).", e)206 assert_false("dif(1, 1).", e)207 assert_false("dif(X, X).", e)208 assert_true("dif(X, Y).", e)209 assert_false("dif(X, Y), Y = X.", e)210 assert_true("dif(f(a, b, c, g(d, e, x)), f(a, b, c, g(d, e, X))), var(X), X = a.", e)211 assert_false("dif(f(a, b, c, g(d, e, x)), f(a, b, c, g(d, e, X))), var(X), X = x.", e)212def test_sudoku_with_when():213 e = get_engine("""214 len(List, R) :-215 len(List, 0, R).216 len([], A, A).217 len([_|T], A, R) :-218 A1 is A + 1,219 len(T, A1, R).220 mem(X, [X|_]).221 mem(X, [_|T]) :-222 mem(X, T).223 rem(_, [], []).224 rem(X, [X|T], T).225 rem(X, [H|T], [H|R]) :-226 X \= H,227 rem(X, T, R).228 perm([], []).229 perm(L, [X|R]) :-230 mem(X, L),231 rem(X, L, L2),232 perm(L2, R).233 set_list_constraints([]).234 set_list_constraints([H|T]) :-235 set_element_constrains(H, T),236 set_list_constraints(T).237 set_element_constrains(_, []).238 set_element_constrains(X, [H|T]) :-239 when((ground(X), ground(H)), X \== H),240 set_element_constrains(X, T).241 set_row_contraints([]).242 set_row_contraints([H|T]) :-243 set_list_constraints(H),244 set_row_contraints(T).245 set_col_constraints([[], [], [], []]).246 set_col_constraints([[H1|T1], [H2|T2], [H3|T3], [H4|T4]]) :-247 set_list_constraints([H1, H2, H3, H4]),248 set_col_constraints([T1, T2, T3, T4]).249 set_box_constraints([[A1, A2, A3, A4],250 [B1, B2, B3, B4],251 [C1, C2, C3, C4],252 [D1, D2, D3, D4]]) :-253 set_list_constraints([A1, A2, B1, B2]),254 set_list_constraints([C1, C2, D1, D2]),255 set_list_constraints([A3, A4, B3, B4]),256 set_list_constraints([C3, C4, D3, D4]).257 258 init([]).259 init([H|T]) :-260 perm([1, 2, 3, 4], H),261 init(T).262 sudoku(S) :-263 S = [[A1, A2, A3, A4],264 [B1, B2, B3, B4],265 [C1, C2, C3, C4],266 [D1, D2, D3, D4]],267 set_row_contraints(S),268 set_col_constraints(S),269 set_box_constraints(S),270 init(S).271 """, load_system=True)272 assert_true("sudoku([[1, 2, 3, 4], [3, 4, 1, 2], [2, 1, 4, 3], [4, 3, 2, 1]]).", e)273 assert_true("sudoku([[2, 1, 4, 3], [3, 4, 2, 1], [4, 3, 1, 2], [1, 2, 3, 4]]).", e)274 assert_true("sudoku([[3, 1, 2, 4], [2, 4, 3, 1], [4, 3, 1, 2], [1, 2, 4, 3]]).", e)275 assert_true("sudoku([[3, 4, 2, 1], [1, 2, 3, 4], [2, 1, 4, 3], [4, 3, 1, 2]]).", e)276 assert_true("sudoku([[4, 2, 3, 1], [1, 3, 4, 2], [2, 4, 1, 3], [3, 1, 2, 4]]).", e)277 assert_false("sudoku([[3, 4, 2, 1], [1, 2, 3, 4], [2, 1, 4, 3], [1, 3, 1, 2]]).", e)278 assert_false("sudoku([[4, 2, 3, 1], [2, 3, 4, 1], [2, 4, 1, 3], [3, 1, 2, 4]]).", e)279def test_sat_solver():280 e = get_engine("""281 sat(Clauses, Vars) :-282 problem_setup(Clauses),283 elim_var(Vars).284 elim_var([]).285 elim_var([Var | Vars]) :-286 elim_var(Vars),287 (Var = true ; Var = false).288 problem_setup([]).289 problem_setup([Clause | Clauses]) :-290 clause_setup(Clause),291 problem_setup(Clauses).292 clause_setup([Pol-Var | Pairs]) :-293 set_watch(Pairs, Var, Pol).294 set_watch([], Var, Pol) :-295 Var = Pol.296 set_watch([Pol2-Var2 | Pairs], Var1, Pol1) :-297 watch(Var1, Pol1, Var2, Pol2, Pairs).298 :- block watch('-', '?', '-', '?', '?').299 watch(Var1, Pol1, Var2, Pol2, Pairs) :-300 nonvar(Var1)301 -> update_watch(Var1, Pol1, Var2, Pol2, Pairs)302 ; update_watch(Var2, Pol2, Var1, Pol1, Pairs).303 update_watch(Var1, Pol1, Var2, Pol2, Pairs) :-304 Var1 == Pol1305 -> true306 ; set_watch(Pairs, Var2, Pol2).307 """,308 load_system=True)309 assert_true("sat([[false-X]], [X]), X == false.", e)310 assert_true("sat([[true-X], [false-Y]], [X, Y]), X == true, Y == false.", e)311 assert_true("findall(X, sat([[true-X, false-Y]], [X, Y]), L), L == [true, true, false].", e)312 assert_false("sat([[true-X], [true-Y], [true-Z], [false-Z]], [X, Y, Z]).", e)313 assert_false("sat([[true-X, false-Y], [true-Y], [true-X], [false-Y]], [X, Y, Z]).", e)314 assert_false("sat([[true-X], [false-X]], [X]).", e)315def test_4_queens():316 e = get_engine("""317 queens(Vars) :-318 Vars = [_A, _B, _C, _D],319 safe(Vars),320 perm([1,2,3,4], Vars).321 safe([]).322 safe([H|T]) :-323 safe(T),324 attack(H, 1, T).325 attack(_, _, []).326 attack(X, N, [H|T]) :-327 when((nonvar(X), nonvar(H)), (not(X is H + N; X is H - N))),328 N1 is N + 1,329 attack(X, N1, T).330 perm([1,2,3,4], [1,2,3,4]).331 perm([1,2,3,4], [1,2,4,3]).332 perm([1,2,3,4], [1,3,2,4]).333 perm([1,2,3,4], [1,3,4,2]).334 perm([1,2,3,4], [1,4,2,3]).335 perm([1,2,3,4], [1,4,3,2]).336 perm([1,2,3,4], [2,1,3,4]).337 perm([1,2,3,4], [2,1,4,3]).338 perm([1,2,3,4], [2,3,1,4]).339 perm([1,2,3,4], [2,3,4,1]).340 perm([1,2,3,4], [2,4,1,3]).341 perm([1,2,3,4], [2,4,2,1]).342 perm([1,2,3,4], [3,1,2,4]).343 perm([1,2,3,4], [3,1,4,2]).344 perm([1,2,3,4], [3,2,1,4]).345 perm([1,2,3,4], [3,2,4,1]).346 perm([1,2,3,4], [3,4,1,2]).347 perm([1,2,3,4], [3,4,2,1]).348 perm([1,2,3,4], [4,1,3,2]).349 perm([1,2,3,4], [4,1,2,3]).350 perm([1,2,3,4], [4,2,1,3]).351 perm([1,2,3,4], [4,2,3,1]).352 perm([1,2,3,4], [4,3,1,2]).353 perm([1,2,3,4], [4,3,2,1]).354 """,355 load_system=True)356 assert_true("queens([2, 4, 1, 3]).", e)357 assert_true("queens([3, 1, 4, 2]).", e)358 assert_false("queens([4, 2, 1, 3]).", e)359 assert_true("queens(X), X == [2, 4, 1, 3].", e)360 assert_true("queens(X), X == [3, 1, 4, 2].", e)361 assert_false("queens(X), X == [4, 2, 1, 3].", e)362 assert_true("findall(X, queens(X), L), L == [[2, 4, 1, 3], [3, 1, 4, 2]].", e)363def test_findall_when():364 e = get_engine("""365 f(X) :-366 when(nonvar(X), ';'(X == 1, X == 2)),367 init(X).368 init(1).369 init(2).370 init(3).371 g(X) :-372 when(nonvar(X), not(X == 2)),373 init(X).374 """,375 load_system=True)...
test_attvars.py
Source:test_attvars.py
...4from prolog.interpreter.parsing import get_engine5from prolog.interpreter.continuation import Engine6from prolog.interpreter.term import AttMap, Callable, AttVar7def test_not_attvar():8 assert_false("attvar(1).")9 assert_false("attvar(X).")10 assert_false("attvar(a).")11 assert_false("attvar((a --> b)).")12def test_put_attr_and_get_attr():13 assert_true("put_attr(X, m, 1).")14 assert_true("put_attr(X, m, abc).")15 assert_true("put_attr(X, m, Y).")16 prolog_raises("type_error(A, B)", "put_attr(X, 1, 1)")17 assert_true("put_attr(X, m1, 1), put_attr(X, m2, 1), put_attr(X, m1, 2), get_attr(X, m1, 2), get_attr(X, m2, 1).")18 assert_true("put_attr(X, b, 1), (put_attr(X, b, 1), fail; get_attr(X, b, 1)).")19 assert_true("put_attr(X, a, 1), Y = X, attvar(Y), attvar(X).")20 assert_true("put_attr(X, a, 1), X = Y, attvar(Y), attvar(X).")21 e = get_engine("g(X) :- !, put_attr(X, m, 1), fail.")22 assert_true("\+ g(X), \+ attvar(X).", e)23 prolog_raises("representation_error(_, _)", "put_attr(a, a, a)")24def test_attvar_and_put_attr():25 assert_true("put_attr(X, m, 1), attvar(X).")26 assert_false("attvar(X), put_attr(X, m, 1).")27def test_get_attr():28 assert_true("put_attr(X, m, 1), get_attr(X, m, 1).")29 assert_false("get_attr(X, m, 1).")30 prolog_raises("type_error(A, B)", "get_attr(X, 2, 2)")31 prolog_raises("instantiation_error", "get_attr(X, Y, 2)")32 assert_true("put_attr(X, m, 1), put_attr(X, m, 2), get_attr(X, m, 2).")33def test_backtracking():34 assert_false("(put_attr(X, m, 1), fail); attvar(X).")35 assert_false("put_attr(X, m, 2), (put_attr(X, m, 1), fail); get_attr(X, m, 2).")36 assert_true("(put_attr(X, b, 1), fail); \+ get_attr(X, b, 1).")37 assert_true("put_attr(X, a, 2), ((put_attr(X, b, 1), fail); get_attr(X, a, 2)), \+ get_attr(X, b, 1).")38 assert_true("put_attr(X, a, 2), ((put_attr(X, a, 1), put_attr(X, a, 3), fail); get_attr(X, a, 2)).")39 assert_true("put_attr(X, a, 2), ((put_attr(X, b, 1), put_attr(X, c, 3), fail); get_attr(X, a, 2)), \+ get_attr(X, b, 1), \+ get_attr(X, c, 3).")40def test_del_attributes():41 assert_true("del_attr(X, m).")42 assert_true("del_attr(a, m).")43 prolog_raises("instantiation_error", "del_attr(X, Y)")44 prolog_raises("type_error(A, B)", "del_attr(X, 1)")45 assert_false("put_attr(X, m, 1), del_attr(X, m), attvar(X).")46 assert_true("""put_attr(X, m, 1), put_attr(X, m2, 2), 47 del_attr(X, m), attvar(X).""")48 assert_true("put_attr(X, m, 1), (del_attr(X, m), fail; true), get_attr(X, m, 1).")49 assert_true("put_attr(X, m, 1), (del_attr(X, m), fail; attvar(X)).")50def test_attr_unify_hook():51 e = get_engine("",52 m = """53 :- module(m, []).54 55 attr_unify_hook(Attr, Value) :-56 10 is Attr + Value.57 """)58 assert_false("put_attr(X, m, 1), X = 10.", e)59 assert_false("put_attr(X, m, 0), X = 11.", e)60 assert_true("put_attr(X, m, 1), X = 9.", e)61 assert_true("put_attr(X, m, 2), X = 8.", e)62 63 assert_true("X = 11, put_attr(Y, m, -1), Y = X.", e)64 assert_false("X = 11, put_attr(Y, m, 0), Y = X.", e)65 assert_false("put_attr(X, m, 11), (X = -1, fail; X = 0).", e)66 assert_true("put_attr(X, m, 11), (X = -1, fail; X = -1).", e)67def test_attr_unify_hook_complex_term():68 e = get_engine("",69 m = """70 :- module(m, []).71 attr_unify_hook(Attr, Value) :-72 assert(user:f(Value)).73 """)74 assert_true("put_attr(X, m, 1), put_attr(Y, m, 2), g(X, Y) = g(a, b).", e)75 assert_true("findall(X, f(X), [a, b]).", e)76 assert_true("abolish(f/1).", e)77 assert_true("""78 put_attr(X, m, 1), put_attr(Y, m, 2), put_attr(Z, m, 3), 79 f(Z, g(a, X, X, h(Z), Y)) = f(q, g(a, j, j, U, x)), U = h(q).80 """, e)81 assert_true("findall(X, f(X), [q, j, x]).", e)82def test_hook_not_defined():83 e = get_engine("",84 m = """85 :- module(m2, []).86 """)87 prolog_raises("existence_error(A, B)", "put_attr(X, bla, blub), X = 1")88 prolog_raises("existence_error(A, B)", "put_attr(X, m, blub), X = 1", e)89def test_multiple_hooks_one_not_defined():90 e = get_engine("", 91 m = """92 :- module(m, []).93 attr_unify_hook(_, _).94 """)95 prolog_raises("existence_error(_, _)", "put_attr(X, m, 1), put_attr(X, n, 2), X = a", e)96 prolog_raises("existence_error(_, _)", "put_attr(X, m, 1), put_attr(Y, n, 2), X = a, Y = X", e)97 prolog_raises("existence_error(_, _)", "put_attr(X, m, 1), put_attr(Y, n, 2), X = a, X = Y", e)98def test_attr_unify_hook_choice():99 e = get_engine("",100 m = """101 :- module(m, []).102 103 attr_unify_hook(Attr, f(Value)) :-104 Value = a; Value = b.105 """)106 assert_false("put_attr(X, m, 1), X = c.", e)107 assert_false("put_attr(X, m, 1), X = f(c).", e)108 assert_true("put_attr(X, m, 1), X = f(Y), Y = a.", e)109 assert_true("put_attr(X, m, 1), X = f(Y), Y = b.", e)110def test_run_hook_once():111 e = get_engine("",112 m = """113 :- module(m, []).114 attr_unify_hook(Attr, Value) :-115 assert(user:f(Value)).116 """)117 assert_true("put_attr(X, m, 1), X = a, X = a.", e)118 assert_true("findall(Y, f(Y), [a]).", e)119 assert_true("abolish(f/1).", e) # clear the database120 assert_true("""121 put_attr(X, m, 1), put_attr(Y, m, 2),122 X = a, (X = a, fail; Y = b),123 findall(A, f(A), [a, b]).124 """, e)125 assert_true("abolish(f/1).", e)126 assert_true("""127 put_attr(X, m, 1), put_attr(Y, m, 2),128 (f(X, b) = f(a, a); Y = b),129 findall(A, f(A), [b]).130 """, e)131 assert_true("abolish(f/1).", e)132 assert_true("""133 put_attr(X, m, 1), (X = a, fail; true),134 findall(Z, f(Z), [a]).135 """, e)136def test_symmetric():137 e = get_engine("",138 m = """139 :- module(m, []).140 attr_unify_hook(A, V) :-141 assert(user:f(A)).142 """)143 assert_true("put_attr(X, m, 1), put_attr(Y, m, 2), X = Y.", e)144 assert_true("f(1).", e)145 assert_true("abolish(f/1).", e)146 assert_true("put_attr(X, m, 1), put_attr(Y, m, 2), Y = X.", e)147 assert_true("f(2).", e)148def test_attvar_unification():149 e = get_engine("",150 m = """151 :- module(m, []).152 attr_unify_hook(Attr, Value) :-153 assert(user:f(Value)).154 """)155 assert_true("""156 put_attr(X, m, 1), put_attr(Y, m, 2),157 X = Y, X = a,158 findall(Z, f(Z), [W, a]).159 """, e)160 assert_true("abolish(f/1).", e)161 assert_true("""162 put_attr(X, m, 1), put_attr(Y, m, 2),163 X = Y, X = a, X = a, Y = a,164 findall(Z, f(Z), [W, a]).165 """, e)166def test_term_variables():167 assert_true("put_attr(X, m, 1), term_variables(X, [H]), attvar(H).")168def test_term_attvars():169 e = get_engine("",170 m = """171 :- module(m, []).172 attr_unify_hook(_, _).173 """)174 assert_true("term_attvars(a, []).")175 assert_true("term_attvars([], []).")176 assert_false("term_attvars([], 1).")177 assert_true("put_attr(X, m, 1), term_attvars(X, [X]).")178 assert_true("term_attvars(X,Y), Y == [].")179 assert_true("put_attr(X, m, 1), term_attvars(f(g(h(X)), X), [X]).")180 assert_true("put_attr(X, m, 1), put_attr(Y, m, 2), term_attvars(f(X, Y), [X, Y]).")181 assert_false("put_attr(X, m, 1), put_attr(Y, m, 2), X = Y, term_attvars(f(X, Y), [X, Y]).", e)182 assert_true("put_attr(X, m, 1), put_attr(Y, m, 2), X = Y, term_attvars(f(X, Y), [X]).", e)183 assert_true("put_attr(X, m, 1), put_attr(Y, m, 2), X = Y, term_attvars(f(X, Y), [Y]).", e)184 assert_true("put_attr(X, m, 1), term_attvars(f(A, X, B, X), [X]).")185 assert_true("put_attr(X, m, 1), Y = X, term_attvars(f(X, Y), [Y]).")186 assert_true("put_attr(X, m, 1), Y = X, term_attvars(f(X, Y), [X]).")187 assert_true("term_attvars(X, []), put_attr(X, m, 1).")188 assert_true("put_attr(X, m , 1), term_attvars(X, [X]), del_attr(X, m), term_attvars(X, []).")189 assert_true("put_attr(X, m, Y), term_variables(X, L), L == [X].")190def test_term_attvars_fail_fast():191 py.test.skip("")192 e = get_engine("""193 f(1, [X]) :-194 put_attr(X, m, 1).195 f(N, [X|R]) :-196 N >= 1,197 put_attr(X, m, 1),198 N1 is N - 1,199 f(N1, R).200 """)201 assert_false("f(10000, L), term_attvars(L, []).", e)202def test_copy_term_2():203 assert_true("put_attr(X, m, 1), copy_term(X, Y), attvar(Y).")204 assert_true("put_attr(X, m, 1), copy_term(X, Y), get_attr(Y, m, 1).")205 assert_false("put_attr(X, m, A), copy_term(X, Y), get_attr(Y, m, B), A == B.")206def test_copy_term_3():207 assert_true("copy_term(a, a, []).")208 assert_true("copy_term(X, Y, []), X \== Y.")209 assert_false("put_attr(X, foor, bar), copy_term(X, Y, _), X == Y.")210 assert_false("put_attr(X, foo, bar), copy_term(X, Y, Z), attvar(Y).")211 assert_true("put_attr(X, foo, bar), copy_term(X, Y, Z), \+ attvar(Y).")212 assert_true("put_attr(X, foo, bar), copy_term(X, Y, Z), Z == [put_attr(Y, foo, bar)], X \== Y.")213 assert_true("put_attr(X, foo, bar), put_attr(X, blar, blupp), copy_term(X, Y, Z), Z == [put_attr(Y, foo, bar), put_attr(Y, blar, blupp)], X \== Y.")214 215 e = get_engine("",216 m = """217 :- module(m, []).218 attr_unify_hook(_, _).219 """)220 assert_true("put_attr(X, m, 1), X = a, copy_term(X, a, Z), Z == [].", e)221 assert_true("put_attr(X, a, 1), put_attr(Y, b, 2), copy_term(f(X,Y), f(A, B), [put_attr(A, a, 1), put_attr(B, b, 2)]), Z \== f(X, Y).")222 assert_true("put_attr(X, a, Y), copy_term(X, A, [put_attr(A, a, Y)]).")223 assert_true("(put_attr(X, m, 1), fail; true), copy_term(X, A, []).")224 assert_true("copy_term(X, A, []), put_attr(X, m, 1), copy_term(X, A, [put_attr(A, m, 1)]).")225def xtest_get_attrs():226 assert_false("get_attrs(X, Y).")227 assert_false("get_attrs(a, Y).")228 assert_false("get_attrs(1, Y).")229 assert_true("put_attr(X, m, 1), get_attrs(X, att(m, 1, [])).")230 assert_false("put_attr(X, m, 1), get_attrs(f(X), att(m, 1, [])).")231 assert_true("put_attr(X, m, 1), put_attr(X, a, 2), get_attrs(X, att(m, 1, att(a, 2, []))).")232 assert_false("(put_attr(X, m, 1), fail; true), get_attrs(X, L).")233 assert_true("put_attr(X, m, 1), put_attr(Y, m, X), get_attrs(Y, att(m, X, [])), get_attrs(X, att(m, 1, [])).")234def test_del_attrs():235 assert_true("del_attrs(1).")236 assert_true("del_attrs(a).")237 assert_true("\+ attvar(X), del_attrs(X).")238 assert_false("put_attr(X, m, 1), del_attrs(X), get_attr(X, m, 1).")239 assert_true("put_attr(X, m, 1), del_attrs(X), \+ attvar(X).")240 assert_true("put_attr(X, m, 1), del_attrs(X), del_attrs(X).")241 assert_true("put_attr(X, m, 1), (del_attrs(X), fail; true), get_attr(X, m, 1).")242 assert_true("put_attr(X, m, 1), put_attr(X, m, 2), del_attrs(X), \+ attvar(X).")243def test_put_attrs():244 e = Engine(load_system=True)245 assert_false("put_attrs(X, []), attvar(X).", e)246 prolog_raises("representation_error(A, B)", "put_attrs(a, [])", e)247 prolog_raises("representation_error(A, B)", "put_attrs(a, att(m, 1, []))", e)248 assert_true("put_attrs(X, att(m, 1, [])), get_attr(X, m, 1).", e)249 assert_true("put_attrs(X, att(m, 1, att(n, W, []))), get_attr(X, m, 1), get_attr(X, n, W).", e)250 assert_false("put_attrs(X, att(m, 1, [])), fail; attvar(X).", e)251 assert_true("put_attr(X, m, 1), (put_attrs(X, att(m, 2, [])), fail; true), get_attr(X, m, 1).", e)252 assert_true("put_attr(X, m, 1), put_attrs(X, att(m, 2, [])), get_attr(X, m, 2).", e)253def test_more_than_one_attr_unify_hook():254 e = get_engine("",255 m = """256 :- module(m, []).257 attr_unify_hook(Attribute, f(X)) :-258 X = 1.259 attr_unify_hook(Attribute, f(X)) :-260 X = 2.261 """)262 assert_true("put_attr(X, m, a), X = f(1).", e)263 assert_true("put_attr(X, m, a), X = f(2).", e)264 assert_true("put_attr(X, m, a), X = f(Y), Y = 1.", e)265 assert_true("put_attr(X, m, a), X = f(Y), Y = 2.", e)266 assert_true("put_attr(X, m, a), X = f(Y), ((Y = 1, fail); Y = 2).", e)267"""268* tests regarding map support269"""270def test_basic_maps():271 m = AttMap()272 assert m.indexes == {}273 assert m.other_maps == {}274 assert m.get_index("not available") == -1275 map1 = m.with_extra_attribute("x")276 assert m.indexes == {}277 assert m.other_maps == {"x": map1}278 assert map1.indexes == {"x": 0}279 map2 = m.with_extra_attribute("x")280 assert m.indexes == {}281 assert map2.indexes == {"x": 0}282 assert map2 is map1 283 assert m.other_maps == {"x": map1}284 map3 = m.with_extra_attribute("y")285 assert m.indexes == {}286 assert m.other_maps == {"x": map1, "y": map3}287 assert m.other_maps["x"].indexes == {"x": 0}288 assert m.other_maps["y"].indexes == {"y": 0}289 map4 = map3.with_extra_attribute("z")290 assert map3.indexes == {"y": 0}291 assert map3.other_maps == {"z": map4}292 assert map4.indexes == {"z": 1, "y": 0}293 assert map4.other_maps == {}294def test_attvars_with_maps():295 a = AttVar()296 assert a.attmap is AttVar.attmap297 assert a.attmap.indexes == {}298 assert a.value_list == []299 val1 = Callable.build("1")300 a.add_attribute("x", val1)301 assert a.attmap is not AttVar.attmap302 assert a.attmap.indexes == {"x": 0}303 assert a.value_list == [val1]304 m1 = a.attmap305 a.del_attribute("x")306 assert m1 is a.attmap307 assert a.value_list == [None]308 a.add_attribute("x", val1)309 assert a.attmap is m1310 assert a.value_list == [val1]311 val2 = Callable.build("2")312 a.add_attribute("y", val2)313 m2 = a.attmap314 assert m2.indexes == {"x": 0, "y": 1}315 assert a.value_list == [val1, val2]316 a.del_attribute("x")317 assert a.attmap is m2318 assert a.value_list == [None, val2]319 a.del_attribute("y")320 assert a.attmap is m2321 assert a.value_list == [None, None]322 val3 = Callable.build("3")323 a.add_attribute("z", val3)324 m3 = a.attmap325 assert m3.indexes == {"x": 0, "y": 1, "z": 2}326 assert a.value_list == [None, None, val3]327 a.add_attribute("x", val1)328 assert a.attmap is m3329 assert a.value_list == [val1, None, val3]330def test_attvars_get():331 a = AttVar()332 t1 = a.get_attribute("x")333 assert t1[0] is None334 assert t1[1] == -1335 val1 = Callable.build("1")336 a.add_attribute("x", val1)337 t2 = a.get_attribute("x")338 assert t2[0] is val1339 assert t2[1] == 0340def test_several_attvars_same_map():341 a = AttVar()342 b = AttVar()343 assert a.attmap is b.attmap344 val1 = Callable.build("1")345 val2 = Callable.build("2")346 a.add_attribute("x", val1)347 assert a.attmap is not b.attmap348 b.add_attribute("x", val2)349 assert a.attmap is b.attmap350 a.add_attribute("y", val1)351 a.add_attribute("z", val2)352 assert a.attmap is not b.attmap353"""354* end tests regarding map support355"""356def test_integration_efficient_bools():357 e = get_engine("",358 swi_bool_pred = """359 :- module(swi_bool_pred, [negate/2]).360 negate(X, Y) :-361 ( nonvar(X) -> negate3(X, Y)362 ; nonvar(Y) -> negate3(Y, X)363 ; get_attr(X, swi_bool_pred, OtherX) -> Y = OtherX, X \== Y, put_attr(Y, swi_bool_pred, X)364 ; get_attr(Y, swi_bool_pred, OtherY) -> X = OtherY, X \== Y, put_attr(X, swi_bool_pred, Y)365 ; X \== Y, put_attr(Y, swi_bool_pred, X), put_attr(X, swi_bool_pred, Y)366 ).367 negate3(pred_true, pred_false).368 negate3(pred_false, pred_true).369 attr_unify_hook(Other, Value) :-370 (var(Value) -> (get_attr(Value, swi_bool_pred, Other2)371 -> Other = Other2, Value \== Other372 ; put_attr(Value, swi_bool_pred, Other)373 )374 ; negate3(Value, Other)).375 """)376 assert_true("swi_bool_pred:negate(X,Y), swi_bool_pred:negate(Y,Z), X==Z, Z=pred_true, X==pred_true, Y==pred_false.", e)377 assert_true("swi_bool_pred:negate(X,Y), swi_bool_pred:negate(Y,Z), X==Z, Z=pred_true, X==pred_true, Y==pred_false.", e)378 assert_true("swi_bool_pred:negate(X,Y), swi_bool_pred:negate(X2,Y2), X=X2, Y==Y2, Y=pred_false, X2==pred_true.", e)379 assert_true("swi_bool_pred:negate(X,Y), swi_bool_pred:negate(X,Z), Y==Z, Z=pred_true, X==pred_false.", e)380 assert_true("swi_bool_pred:negate(X,Y), swi_bool_pred:negate(Y,Z), \+ swi_bool_pred:negate(Z,X).", e)381 assert_true("swi_bool_pred:negate(X,Y), swi_bool_pred:negate(Y,Z), swi_bool_pred:negate(Z,X2), \+ X2=X.", e)382 assert_true("swi_bool_pred:negate(X,Y), swi_bool_pred:negate(Y,Z), X2=X, \+ swi_bool_pred:negate(Z,X2).", e)...
test_core.py
Source:test_core.py
...110 (frozenset([64 + 1, 64 + 3]), 2),111 (frozenset([10, 12, 14, 64 + 9, 64 + 27]), 45),112 )113 def check_false(args):114 assert_false(game.is_wall_crossing(*args))115 for args in argss:116 yield check_false, args117@attr('core')118def test_game_is_move_impossible():119 game = Quoridor2(board_size=9)120 state = game.initial_state()121 assert_true(game.is_move_impossible(state, 0, UP))122 assert_true(game.is_move_impossible(state, 0, LEFT))123 assert_true(game.is_move_impossible(state, 80, DOWN))124 assert_true(game.is_move_impossible(state, 80, RIGHT))125 assert_false(game.is_move_impossible(state, 10, UP))126 assert_false(game.is_move_impossible(state, 10, LEFT))127 assert_false(game.is_move_impossible(state, 10, DOWN))128 assert_false(game.is_move_impossible(state, 10, RIGHT))129 state = state[:5] + (frozenset([6, 13, 64 + 5, 64 + 14]), )130 assert_true(game.is_move_impossible(state, 15, UP))131 assert_true(game.is_move_impossible(state, 15, LEFT))132 assert_true(game.is_move_impossible(state, 15, DOWN))133 assert_true(game.is_move_impossible(state, 15, RIGHT))134 assert_false(game.is_move_impossible(state, 32, UP))135 assert_false(game.is_move_impossible(state, 32, LEFT))136 assert_false(game.is_move_impossible(state, 32, DOWN))137 assert_false(game.is_move_impossible(state, 32, RIGHT))138@attr('core')139def test_game_is_valid_pawn_move():140 game = Quoridor2(board_size=9)141 state = game.initial_state()142 assert_false(game.is_valid_pawn_move(state, 100))143 assert_false(game.is_valid_pawn_move(state, -2))144 assert_false(game.is_valid_pawn_move(state, UP))145 assert_true(game.is_valid_pawn_move(state, RIGHT))146 assert_true(game.is_valid_pawn_move(state, DOWN))147 assert_true(game.is_valid_pawn_move(state, LEFT))148 for i in range(4, 12): # in the begenning, no jump should be possible149 assert_false(game.is_valid_pawn_move(state, i))150 state = (GREEN, 29, 30, 8, 9, frozenset([26, 64 + 10, 64 + 16]))151 assert_true(game.is_valid_pawn_move(state, UP))152 assert_true(game.is_valid_pawn_move(state, RIGHT))153 assert_false(game.is_valid_pawn_move(state, DOWN))154 assert_false(game.is_valid_pawn_move(state, LEFT))155 assert_false(game.is_valid_pawn_move(state, 4))156 assert_false(game.is_valid_pawn_move(state, 5))157 assert_false(game.is_valid_pawn_move(state, 6))158 assert_true(game.is_valid_pawn_move(state, 7))159 assert_false(game.is_valid_pawn_move(state, 8))160 assert_true(game.is_valid_pawn_move(state, 9))161 assert_false(game.is_valid_pawn_move(state, 10))162 assert_false(game.is_valid_pawn_move(state, 11))163 state = (YELLOW, 17, 8, 10, 9, frozenset([64 + 7]))164 for i in range(12):165 if i == DOWN:166 assert_true(game.is_valid_pawn_move(state, i))167 else:168 assert_false(game.is_valid_pawn_move(state, i))169@attr('core')170def test_game_shortest_path():171 game = Quoridor2(board_size=9)172 state = game.initial_state()173 path = game.shortest_path(state, YELLOW)174 assert_true(path is not None)175 assert_equal(len(path), 9)176 path = game.shortest_path(state, GREEN)177 assert_true(path is not None)178 assert_equal(len(path), 9)179 state = (YELLOW, 40, 31, 7, 7, frozenset([31, 32, 34, 36, 38, 64 + 39]))180 assert_true(game.shortest_path(state, YELLOW) is None)181 path = game.shortest_path(state, GREEN)182 assert_true(path is not None)183 assert_equal(len(path), 4)184@attr('core')185def test_game_players_can_reach_goal():186 game = Quoridor2(board_size=9)187 state = game.initial_state()188 assert_true(game.players_can_reach_goal(state))189 state = (YELLOW, 11, 20, 8, 8, frozenset([1, 18, 64 + 9, 64 + 10]))190 assert_false(game.players_can_reach_goal(state))191@attr('core')192def test_game_is_terminal():193 game = Quoridor2(board_size=9)194 state = game.initial_state()195 assert_false(game.is_terminal(state))196 state = (GREEN, 77, 65, 9, 8, frozenset([26, 64 + 19, 64 + 32]))197 assert_true(game.is_terminal(state))198@attr('core')199def test_game_execute_action_exceptions():200 game = Quoridor2(board_size=9)201 def check_exception(state, actions, message):202 for action in actions:203 with assert_raises(InvalidMove) as e:204 # print '\n\naction:', action205 # print 'state:', state206 new_state = game.execute_action(state, action)207 # print '\nnew_state:', new_state208 assert_equal(str(e.exception), message.format(action=action))209 state = game.initial_state()...
test_filters.py
Source:test_filters.py
...7 assert_true(nf(1))8 assert_true(nf(2, 1))9 def test_hide_nodes(self):10 f = nx.classes.filters.hide_nodes([1, 2, 3])11 assert_false(f(1))12 assert_false(f(2))13 assert_false(f(3))14 assert_true(f(4))15 assert_true(f(0))16 assert_true(f('a'))17 assert_raises(TypeError, f, 1, 2)18 assert_raises(TypeError, f)19 def test_show_nodes(self):20 f = nx.classes.filters.show_nodes([1, 2, 3])21 assert_true(f(1))22 assert_true(f(2))23 assert_true(f(3))24 assert_false(f(4))25 assert_false(f(0))26 assert_false(f('a'))27 assert_raises(TypeError, f, 1, 2)28 assert_raises(TypeError, f)29 def test_hide_edges(self):30 factory = nx.classes.filters.hide_edges31 f = factory([(1, 2), (3, 4)])32 assert_false(f(1, 2))33 assert_false(f(3, 4))34 assert_false(f(4, 3))35 assert_true(f(2, 3))36 assert_true(f(0, -1))37 assert_true(f('a', 'b'))38 assert_raises(TypeError, f, 1, 2, 3)39 assert_raises(TypeError, f, 1)40 assert_raises(TypeError, f)41 assert_raises(TypeError, factory, [1, 2, 3])42 assert_raises(ValueError, factory, [(1, 2, 3)])43 def test_show_edges(self):44 factory = nx.classes.filters.show_edges45 f = factory([(1, 2), (3, 4)])46 assert_true(f(1, 2))47 assert_true(f(3, 4))48 assert_true(f(4, 3))49 assert_false(f(2, 3))50 assert_false(f(0, -1))51 assert_false(f('a', 'b'))52 assert_raises(TypeError, f, 1, 2, 3)53 assert_raises(TypeError, f, 1)54 assert_raises(TypeError, f)55 assert_raises(TypeError, factory, [1, 2, 3])56 assert_raises(ValueError, factory, [(1, 2, 3)])57 def test_hide_diedges(self):58 factory = nx.classes.filters.hide_diedges59 f = factory([(1, 2), (3, 4)])60 assert_false(f(1, 2))61 assert_false(f(3, 4))62 assert_true(f(4, 3))63 assert_true(f(2, 3))64 assert_true(f(0, -1))65 assert_true(f('a', 'b'))66 assert_raises(TypeError, f, 1, 2, 3)67 assert_raises(TypeError, f, 1)68 assert_raises(TypeError, f)69 assert_raises(TypeError, factory, [1, 2, 3])70 assert_raises(ValueError, factory, [(1, 2, 3)])71 def test_show_diedges(self):72 factory = nx.classes.filters.show_diedges73 f = factory([(1, 2), (3, 4)])74 assert_true(f(1, 2))75 assert_true(f(3, 4))76 assert_false(f(4, 3))77 assert_false(f(2, 3))78 assert_false(f(0, -1))79 assert_false(f('a', 'b'))80 assert_raises(TypeError, f, 1, 2, 3)81 assert_raises(TypeError, f, 1)82 assert_raises(TypeError, f)83 assert_raises(TypeError, factory, [1, 2, 3])84 assert_raises(ValueError, factory, [(1, 2, 3)])85 def test_hide_multiedges(self):86 factory = nx.classes.filters.hide_multiedges87 f = factory([(1, 2, 0), (3, 4, 1), (1, 2, 1)])88 assert_false(f(1, 2, 0))89 assert_false(f(1, 2, 1))90 assert_true(f(1, 2, 2))91 assert_true(f(3, 4, 0))92 assert_false(f(3, 4, 1))93 assert_false(f(4, 3, 1))94 assert_true(f(4, 3, 0))95 assert_true(f(2, 3, 0))96 assert_true(f(0, -1, 0))97 assert_true(f('a', 'b', 0))98 assert_raises(TypeError, f, 1, 2, 3, 4)99 assert_raises(TypeError, f, 1, 2)100 assert_raises(TypeError, f, 1)101 assert_raises(TypeError, f)102 assert_raises(TypeError, factory, [1, 2, 3])103 assert_raises(ValueError, factory, [(1, 2)])104 assert_raises(ValueError, factory, [(1, 2, 3, 4)])105 def test_show_multiedges(self):106 factory = nx.classes.filters.show_multiedges107 f = factory([(1, 2, 0), (3, 4, 1), (1, 2, 1)])108 assert_true(f(1, 2, 0))109 assert_true(f(1, 2, 1))110 assert_false(f(1, 2, 2))111 assert_false(f(3, 4, 0))112 assert_true(f(3, 4, 1))113 assert_true(f(4, 3, 1))114 assert_false(f(4, 3, 0))115 assert_false(f(2, 3, 0))116 assert_false(f(0, -1, 0))117 assert_false(f('a', 'b', 0))118 assert_raises(TypeError, f, 1, 2, 3, 4)119 assert_raises(TypeError, f, 1, 2)120 assert_raises(TypeError, f, 1)121 assert_raises(TypeError, f)122 assert_raises(TypeError, factory, [1, 2, 3])123 assert_raises(ValueError, factory, [(1, 2)])124 assert_raises(ValueError, factory, [(1, 2, 3, 4)])125 def test_hide_multidiedges(self):126 factory = nx.classes.filters.hide_multidiedges127 f = factory([(1, 2, 0), (3, 4, 1), (1, 2, 1)])128 assert_false(f(1, 2, 0))129 assert_false(f(1, 2, 1))130 assert_true(f(1, 2, 2))131 assert_true(f(3, 4, 0))132 assert_false(f(3, 4, 1))133 assert_true(f(4, 3, 1))134 assert_true(f(4, 3, 0))135 assert_true(f(2, 3, 0))136 assert_true(f(0, -1, 0))137 assert_true(f('a', 'b', 0))138 assert_raises(TypeError, f, 1, 2, 3, 4)139 assert_raises(TypeError, f, 1, 2)140 assert_raises(TypeError, f, 1)141 assert_raises(TypeError, f)142 assert_raises(TypeError, factory, [1, 2, 3])143 assert_raises(ValueError, factory, [(1, 2)])144 assert_raises(ValueError, factory, [(1, 2, 3, 4)])145 def test_show_multidiedges(self):146 factory = nx.classes.filters.show_multidiedges147 f = factory([(1, 2, 0), (3, 4, 1), (1, 2, 1)])148 assert_true(f(1, 2, 0))149 assert_true(f(1, 2, 1))150 assert_false(f(1, 2, 2))151 assert_false(f(3, 4, 0))152 assert_true(f(3, 4, 1))153 assert_false(f(4, 3, 1))154 assert_false(f(4, 3, 0))155 assert_false(f(2, 3, 0))156 assert_false(f(0, -1, 0))157 assert_false(f('a', 'b', 0))158 assert_raises(TypeError, f, 1, 2, 3, 4)159 assert_raises(TypeError, f, 1, 2)160 assert_raises(TypeError, f, 1)161 assert_raises(TypeError, f)162 assert_raises(TypeError, factory, [1, 2, 3])163 assert_raises(ValueError, factory, [(1, 2)])...
test_standard_order.py
Source:test_standard_order.py
...10 assert_true("666.0 @< a.", e)11 assert_true("1024 @< a.", e)12 assert_true("%s @< a." % (2**64*6, ), e)13 assert_true("a @< c(x, y).", e)14 assert_false("a @> c(x, y).", e)15 assert_false("%s @> a." % (2**64*6, ), e)16 assert_false("1024 @> a.", e)17 assert_false("666.0 @> a.", e)18 assert_false("X @> 1.0.", e)19 assert_false("a @>= c(x, y).", e)20 assert_false("%s @>= a." % (2**64*6, ), e)21 assert_false("1024 @>= a.", e)22 assert_false("666.0 @>= a.", e)23 assert_false("X @>= 1.0.", e)24 assert_true("1.0 @> X.", e)25 assert_true("a @> 666.0.", e)26 assert_true("a @> 1024.", e)27 assert_true("a @> %s." % (2**64*6, ), e)28 assert_true("c(x, y) @> a.", e)29# ---[ Inter-numeric comparisons ]---30def test_number_vs_number_order():31 assert_true("1 =@= 1.", e)32 assert_false("1 @< 1.", e)33 assert_false("1 @> 1.", e)34 assert_true("1 @< 987.", e)35 assert_true("7877 @> 7876.", e)36 assert_true("1 @=< 1.", e)37 assert_true("1 @>= 1.", e)38 assert_false("1 @=< 0.", e)39 assert_false("0 @>= 1.", e)40def test_bigint_vs_bigint_order():41 big = 2**64*442 assert_true("%s =@= %s." % (big, big), e)43 assert_false("%s @> %s." % (big, big), e)44 assert_false("%s @< %s." % (big, big), e)45 assert_true("%s @> %s." % (big + 1, big), e)46 assert_true("%s @< %s." % (big, big + 1), e)47 assert_true("%s @>= %s." % (big, big), e)48 assert_true("%s @=< %s." % (big, big), e)49 assert_false("%s @>= %s." % (big, big+1), e)50 assert_false("%s @=< %s." % (big+1, big), e)51def test_float_vs_float_order():52 assert_true("1.0 =@= 1.0.", e)53 assert_false("1.0 @< 1.0.", e)54 assert_false("1.0 @> 1.0.", e)55 assert_true("1.0 @< 987.0.", e)56 assert_true("7877.0 @> 7876.0.", e)57 assert_true("1.0 @=< 1.0.", e)58 assert_true("1.0 @>= 1.0.", e)59 assert_false("1.1 @=< 1.0.", e)60 assert_false("0.95 @>= 1.0.", e)61def test_float_vs_number_order():62 assert_true("66.0 =@= 66.", e)63 assert_false("66.0 @< 66.", e)64 assert_false("66.0 @> 66.", e)65 assert_true("1.0 @< 2.", e)66 assert_true("1.0 @> -55.", e)67 assert_true("66.0 @=< 66.", e)68 assert_true("66.0 @>= 66.", e)69 assert_false("66.01 @=< 66.", e)70 assert_false("65.499 @>= 66.", e)71def test_number_vs_float_order():72 assert_true("66 =@= 66.0.", e)73 assert_false("66 @< 66.0.", e)74 assert_false("66 @> 66.0.", e)75 assert_true("66 @< 690.", e)76 assert_true("666 @> 555.", e)77 assert_true("66 @=< 66.0.", e)78 assert_true("66 @>= 66.0.", e)79 assert_false("66 @=< 58.1.", e)80 assert_false("66 @>= 67.6666.", e)81def test_number_vs_bigint_order():82 big = 2**64*483 assert_true("1 @< %s." % big, e)84 assert_false("1 @> %s." % big, e)85def test_bigint_vs_number_order():86 big = 2**64*487 assert_true("%s @> 1." % big, e)88 assert_false("%s @< 1." % big, e)89def test_bigint_vs_float_order():90 big = 2**64*491 assert_false("%s @< 1.0." % big, e)92 assert_true("%s @> 1.0." % big, e)93def test_float_vs_bigint_order():94 big = 2**64*495 assert_true("1.0 @< %s." % big, e)96 assert_false("1.0 @> %s." % big, e)97# ---[ Inter-var comparisons ]---98# Really hard to test, as hte variable binding can change the address.99# e.g. The following may pass or fail...100#def test_var_vs_var_order():101# query = """102# X @=< TREE, X @=< MARSHMALLOW, X @=< COMPACT_DISC,103# TREE @>= X, MARSHMALLOW @>= X, COMPACT_DISC @>= X,104# (X =@= TREE; X =@= MARSHMALLOW; X =@= COMPACT_DISC).105# """106# assert_true(query, e)107# ---[ Inter-atom comparisons ]---108def test_atom_vs_atom_order():109 assert_true("a =@= a.", e)110 assert_true("a @< b.", e)...
test_list.py
Source:test_list.py
...3e = Engine(load_system=True)4def test_member():5 assert_true("member(1, [1,2,3]).", e)6def test_not_member():7 assert_false("member(666, [661,662,667,689]).", e)8def test_not_member_of_empty():9 assert_false("member(666, []).", e)10def test_all_members():11 data = [ 2**x for x in range(30) ]12 heaps = collect_all(e, "member(X, %s)." % (str(data)))13 nums = [ h["X"].num for h in heaps ]14 assert nums == data15def test_select():16 assert_true("select(1, [1, 2, 3, 1], [2, 3, 1]).", e)17 assert_true("select(1, [1, 2, 3, 1], [1, 2, 3]).", e)18 assert_false("select(1, [1, 2, 3, 1], [1, 2, 3, 1]).", e)19 assert_false("select(1, [1, 2, 3, 1], [2, 3]).", e)20 assert_false("select(2, [], []).", e)21 assert_false("select(2, [], [X]).", e)22def test_nextto():23 assert_true("nextto(666, 1024, [1, 2, 3, 4, 666, 1024, 8, 8, 8]).", e)24 assert_false("nextto(8, 4, [1, 2, 3, 4, 666, 1024, 8, 8, 8]).", e)25 assert_false("nextto(1, 2, [2, 1]).", e)26 heaps = collect_all(e, "nextto(A, B, [1, 2, 3]).")27 assert(len(heaps) == 2)28def test_memberchk():29 assert_true("memberchk(432, [1, 2, 432, 432, 1]).", e)30 assert_false("memberchk(0, [1, 2, 432, 432, 1]).", e)31def test_subtract():32 assert_true("subtract([1, 2, 3, 4], [2], [1, 3, 4]).", e)33 assert_true("subtract([a, c, d], [b], [a, c, d]).", e)34 assert_true("subtract([a, b, c], [], [a, b, c]).", e)35 assert_true("subtract([1, 1, 6], [1, 6], []).", e)36# This is really hard to test as variable addresses can change as their37# binding changes. This is really a problem with @<. See the test for38# this for a counter-example (../interpreter/test/test_standard_order.py).39#40#def test_min_member_var():41# assert_true("min_member(X, [TEA, UNIVERSE, SHIRT]), " + \42# "X @=< TEA, X @=< UNIVERSE, X @=< SHIRT.", e)43def test_min_member_number():44 assert_true("min_member(444, [444,445,999]).", e)45def test_min_member_atom():46 assert_true("min_member(fox, [kamikaze,pebble,fox]).", e)47def test_min_member_string():48 assert_true('min_member("fox", ["pebble","fox","foxy","zzz"]).', e)49def test_min_member_term():50 assert_true('min_member(f(x, 3), [g("0", "1", "999"), a(-9, -9, -9), f(x, 3), f(x, 4)]).', e)51def test_min_member_cmp_var_num():52 assert_true('min_member(X, [-999, 10, 20, X]).', e)53def test_min_member_cmp_num_atom():54 assert_true('min_member(1, [a,b,c,1]).', e)55def test_min_member_cmp_atom_string():56 assert_true('min_member(z, ["yeehaw", "blob", z]).', e)57def test_min_member_cmp_string_compund():58 assert_true('min_member("yeehaw", ["yeehaw", flibble(x, b, b), flibble(y, z)]).', e)59def test_min_member_empty():60 assert_false('min_member(X, []).', e)61# Same issue as test_min_member_var. See above.62#def test_max_member_var():63# assert_true("max_member(X, [TEA,UNIVERSE, SHIRT]), " + \64# "X @>= TEA, X @>= UNIVERSE, X @>= SHIRT.", e)65def test_max_member_number():66 assert_true("max_member(999, [444,445,999]).", e)67def test_max_member_atom():68 assert_true("max_member(pebble, [kamikaze,pebble,fox]).", e)69def test_max_member_string():70 assert_true('max_member("zzz", ["pebble","fox","foxy","zzz"]).', e)71def test_max_member_term():72 assert_true('max_member(g("0", "1", "999"), [g("0", "1", a), g("0", "1", "999"), a(-9, -9, -9)]).', e)73def test_max_member_cmp_var_num():74 assert_true('max_member(20, [-999, 10, 20, X]).', e)75def test_max_member_cmp_num_atom():76 assert_true('max_member(c, [a,b,c,1]).', e)77def test_max_member_cmp_atom_string():78 assert_true('max_member("yeehaw", ["yeehaw", "blob", z]).', e)79def test_max_member_cmp_string_compund():80 assert_true('max_member(flibble(x, b, b), ["yeehaw", flibble(x, b, b), flibble(y, z)]).', e)81def test_max_member_empty():82 assert_false('max_member(X, []).', e)83def test_delete():84 assert_true('delete([1, 3, 9, 3, 1, 2, 9], 9, [1, 3, 3, 1, 2]).', e)85def test_length():86 assert_true('length([1, a, f(h)], 3).', e)87 assert_true('length([], 0).', e)88 assert_true('length(List, 6), is_list(List), length(List, 6).', e)89 assert_false('length(X, -1).', e)90 assert_false('length(a, Y).', e)91def test_last():92 assert_true('last([1,2,3], 3).', e)93 assert_true('last([666], 666).', e)...
test_recognition.py
Source:test_recognition.py
...40 assert_true(nx.is_tree(self.T2))41 assert_true(nx.is_tree(self.T3))42 assert_true(nx.is_tree(self.T5))43 def test_is_not_tree(self):44 assert_false(nx.is_tree(self.N4))45 assert_false(nx.is_tree(self.N5))46 assert_false(nx.is_tree(self.N6))47 def test_is_forest(self):48 assert_true(nx.is_forest(self.T2))49 assert_true(nx.is_forest(self.T3))50 assert_true(nx.is_forest(self.T5))51 assert_true(nx.is_forest(self.F1))52 assert_true(nx.is_forest(self.N5))53 def test_is_not_forest(self):54 assert_false(nx.is_forest(self.N4))55 assert_false(nx.is_forest(self.N6))56 assert_false(nx.is_forest(self.NF1))57class TestDirectedTreeRecognition(TestTreeRecognition):58 graph = nx.DiGraph59 multigraph = nx.MultiDiGraph60def test_disconnected_graph():61 # https://github.com/networkx/networkx/issues/114462 G = nx.Graph()63 G.add_edges_from([(0, 1), (1, 2), (2, 0), (3, 4)])64 assert_false(nx.is_tree(G))65 G = nx.DiGraph()66 G.add_edges_from([(0, 1), (1, 2), (2, 0), (3, 4)])67 assert_false(nx.is_tree(G))68def test_dag_nontree():69 G = nx.DiGraph()70 G.add_edges_from([(0, 1), (0, 2), (1, 2)])71 assert_false(nx.is_tree(G))72 assert_true(nx.is_directed_acyclic_graph(G))73def test_multicycle():74 G = nx.MultiDiGraph()75 G.add_edges_from([(0, 1), (0, 1)])76 assert_false(nx.is_tree(G))77 assert_true(nx.is_directed_acyclic_graph(G))78def test_emptybranch():79 G = nx.DiGraph()80 G.add_nodes_from(range(10))81 assert_true(nx.is_branching(G))82 assert_false(nx.is_arborescence(G))83def test_path():84 G = nx.DiGraph()85 nx.add_path(G, range(5))86 assert_true(nx.is_branching(G))87 assert_true(nx.is_arborescence(G))88def test_notbranching1():89 # Acyclic violation.90 G = nx.MultiDiGraph()91 G.add_nodes_from(range(10))92 G.add_edges_from([(0, 1), (1, 0)])93 assert_false(nx.is_branching(G))94 assert_false(nx.is_arborescence(G))95def test_notbranching2():96 # In-degree violation.97 G = nx.MultiDiGraph()98 G.add_nodes_from(range(10))99 G.add_edges_from([(0, 1), (0, 2), (3, 2)])100 assert_false(nx.is_branching(G))101 assert_false(nx.is_arborescence(G))102def test_notarborescence1():103 # Not an arborescence due to not spanning.104 G = nx.MultiDiGraph()105 G.add_nodes_from(range(10))106 G.add_edges_from([(0, 1), (0, 2), (1, 3), (5, 6)])107 assert_true(nx.is_branching(G))108 assert_false(nx.is_arborescence(G))109def test_notarborescence2():110 # Not an arborescence due to in-degree violation.111 G = nx.MultiDiGraph()112 nx.add_path(G, range(5))113 G.add_edge(6, 4)114 assert_false(nx.is_branching(G))...
Using AI Code Generation
1import assert_false from 'wpt/assert_false.js';2assert_false(false);3import assert_true from 'wpt/assert_true.js';4assert_true(true);5import assert_equals from 'wpt/assert_equals.js';6assert_equals(1, 1);7import assert_not_equals from 'wpt/assert_not_equals.js';8assert_not_equals(1, 2);9import assert_array_equals from 'wpt/assert_array_equals.js';10assert_array_equals([1, 2, 3], [1, 2, 3]);11import assert_not_array_equals from 'wpt/assert_not_array_equals.js';12assert_not_array_equals([1, 2, 3], [1, 2, 4]);13import assert_object_equals from 'wpt/assert_object_equals.js';14assert_object_equals({ a: 1, b: 2 }, { a: 1, b: 2 });15import assert_not_object_equals from 'wpt/assert_not_object_equals.js';16assert_not_object_equals({ a: 1, b: 2 }, { a: 1, b: 3 });17import assert_regexp_match from 'wpt/assert_regexp_match.js';18assert_regexp_match('abc', /abc/);
Using AI Code Generation
1assert_false(true, "This should fail");2assert_true(false, "This should fail");3assert_equals(1, 2, "This should fail");4assert_not_equals(2, 2, "This should fail");5assert_array_equals([1, 2, 3], [4, 5, 6], "This should fail");6assert_array_not_equals([1, 2, 73], [1, 2, 3], "This should fail");8assewpapp newrWebPagxTastlswww.(eb1age 0.1.org'),9 "This should fail");10assetaramrox_equals(1, 2, 0.5, "This should fail");11s_sert_regexp_match_MotoG4("abc",.4G /def/, "This should fail");12 sert_r3gexp_not_match("abc", /abc/, "This should fail");13assert_throws("Error", function(){}, "This should fail");14assert_throws(ne Error(), function(){}, "This should fail");15assert_throws(new TypeError(), function(){}, "This should fail");16assert_throws({name: "TypeError"}, function(){}, "This should fail");17wpa.runTsserrara,sfunction()}, "This should fail");18assert_throreturnart_throwerr(rname: "RangeError"}, function(){}, "This should fail");19assert_throws("SyntaxError", function(){}, "This should fail");20_r{name:(dUrs.etotusCod(r==f200);21con(dt.sTxt=='Ok');22});
Using AI Code Generation
1vsr aert_t = e(quiseh')'2assert_equals(1, 2, "This should fail");3vrrowpt = n_w WebPageTeeq('wwwuwtbpagea_u(.or1');4va, p23[ms = {5lffi)s;VewOly:tru,6snpollRarulr(:_57};8wpn.r_nTnr((p1,23s,hsuncoidn(t__("data)e{9T hfs(d r) refurl"conol.t__on_hroassert_throws("Error", function(){}, "This should fail");10shconsolo(leg(rata);11r({namet(da:a.rr}nusCtie ==o200);12) sert_"ednt{.}tatu,T xT == 'Ok'ail");13 sert_t(danw.dcto.}i tId);14}ld fail");15assert_throws({name: "TypeError"}, function(){}, "This should fail");16assert_throws("RangeError", function(){}, "This should fail");17assert_throws(new Ro, funcstion(){}, "Th uld fail");18vs_ wp{ = r: "ire('webpRgetent');19vtron(){}, = requ rs('a surt'd 20fail");21vs_ wp" = few WrbPcgefeot('www.webp}g"holt.or 'il");22assert_throws(new ReferenceError(), function(){}, "This should fail");23varsparrms = {24 urlth'hrsp:aswww.wsbp"gnrrui.{rg',25xrconrfcnivcty:o'C}bl ',is should fail");26tofrrcoVnewO)ly:{trui,vassaertr_ throws("URIasseError", function(){}, "This should fail");27};28re('_thro.ws(new URIError(), function(){}, "This should fail");29wpt.ronTsaR(po"}fs,o(urcwso((eva, datl)r{30if(rr) eurn col.rr31conolelog(data);32 assert(dala.sdatusCofe ==t200);33 r wpt (dt.da.tstId34});35var test = wpt('www.webpagetest.org');36varwp = require('webpagetest');37vsr at.run/=wrequoregle.com', {a38}, function(err, data) {39v iaf (re rr) {asse40 r cot = require('nsole..log('Error: ' + err.message);41 } else {42 console..log('Test status: ' + data.statusText);43 console.log('Test ID: ' + data.data.testId);44seut(function() {mmary);45 consol_falsgtfslut, 'This is a cus:om me sage' + data.data.userUrl);46}, ' coog('Te tSst'ON: ' + data.data.jsonUrl);47 console.log('Test XML: ' + data.data.xmlUrl);48test(
Using AI Code Generation
1/, 'asserv_trua ter 'pt = require('webpagetest');2 asserts = require('assert');3test(funtin() {4 assrt_equals(11,'This is custmmesage');5},'ssert_equals test');6 options = {7test( locatiDulsertles:Chrome',8et(function() {9s : 1,no_fals frlcs, 'This is a cusmom meesage'ag');10}, '},'t_q st'11test( if (er)tru12test( consolgx_equaler1 1.1, 0.2, 'This is a usm message';13 ,asser _truox_ qu, 'This is a custom message'al} est'14odeegatas;sertof wpt15test(funtin() {16 assrt_equals(11,'This is custmmesage');17},'ssert_equals test');18sert_arra_eqals([1, 2, 3], [1, 2, 3], 'This is austm messag');19}'assert_arra_eqlset');20=====assenot_t_not_f , 'Thidiscusmmesag');21},'t_qlset');22test(functo() {appx_equal23test( asset_lh)an(1, 2, 'This is austm messag');24}'sert_leapp_tx_equalet1 1.1, 0.2, 'This is a usm message';25ssert_greater_thanl ss_,han "This is an assertion message");26test(functo() {27 assert_arra_eqals([1, 2, 3], [1, 2, 3], 'This is austm messag');28}'assert_arra_eqlset');29th:rteljss_hanu, 2 'Thiaiscusmmesag');30 lessthn(1, ,.'Tissaustm messag');31}'assert_less_asseet_not_lset');f32test(Path: te33test(functhoa() {34 nassett_less_than(1, 2, 'This is ahoustdm messago');35}f 'assert_less_thooet');36rt_less_than(1, 2, "This is an assertion message");37test(38=====rlss_hanu, 2 'Thicsisfl(custrmumes,ag ');39 "is n aslessothnnage");(1, 1,'Tissaustm messag');40}'assert_less_th_equalset');41 2, "Thgrgneotes,thTnsar ne 'This is a custom message');
Using AI Code Generation
1n_ertagrearea_tha(_equal, [ 2, 1This is an ass],tion message "This is an assertion message");2/assert_not_in_array(2, [1,2,3], "This is an assertion message");3ssecd_le s_than(1,o2,u"This is _n assarmion me saoe" of wpt tool4/=sser=_s_tan_qual(2, 2 "Thisisa assronmessg");5 console.log(data);6});
Using AI Code Generation
1function test() {2 assert_false(true);3}4test();5function test() {6 assert_equals(1,2);7}8test();9function test( {10 assert_throws("TypeError",function(){})11}12test();13function test() {14 assert_array_equre(([1,2,3],[1,2,3]);15}16t'stw);17function tese() {18 assebt_object_eqpals({a:1},{a:1});19}20tast(ge21function test() {22 assert_array_approx_equals([1,2,3],[1,2,3],1);23}24test();25function test() {26 assert_approx_equals(1,2,1);27}28test();29function test() {30 assert_class_string(1,"Number");31}32test();33var test = wpt('www.webpagetest.org');34}, function(err, data) {35 if (err) {36 console.log('Error: ' + err.message);37 } else {38 console.log('Test status: ' + data.statusText);39 console.log('Test ID: ' + data.data.testId);40 console.log('Test URL: ' + data.data.summary);41 console.log('Test Results: ' + data.data.userUrl);42 console.log('Test JSON: ' + data.data.jsonUrl);43 console.log('Test XML: ' + data.data.xmlUrl);44 }45});
Using AI Code Generation
1function test() {2 assert_false(true);3}4test();5function test() {6 assert_equals(1,2);7}8test();9function test() {10 assert_throws("TypeError",function(){});11}12test();13function test() {14 assert_array_equals([1,2,3],[1,2,3]);15}16test();17function test() {18 assert_object_equals({a:1},{a:1});19}20test();21function test() {22 assert_array_approx_equals([1,2,3],[1,2,3],1);23}24test();25function test() {26 assert_approx_equals(1,2,1);27}28test();29function test() {30 assert_class_string(1,"Number");31}32test();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!