
    ni*,                         S r SSKrSSKr " S S5      r " S S5      r " S S5      r " S	 S
5      r " S S5      r " S S5      r	 " S S5      r
g)z
Unit tests for pyreason add operations: add_rule, add_fact, add_annotation_function, etc.
Tests the core API functions for adding content to the pyreason system.
    Nc                   B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)TestAddRule	   zTest add_rule() function.c                 X    [         R                  " 5         [         R                  " 5         gzClean state before each test.Nprresetreset_settingsselfs    f/home/james-whalen/.local/lib/python3.13/site-packages/tests/api_tests/test_pyreason_add_operations.pysetup_methodTestAddRule.setup_method        	

    c                     [         R                  " 5         [         R                  " SS5      n[         R                  " U5        g)z2Test add_rule() works when starting with no rules.test(x) <- fact(x)	test_ruleN)r	   reset_rulesRuleadd_ruler   rules     r   *test_add_rule_creates_rules_list_when_none6TestAddRule.test_add_rule_creates_rules_list_when_none   s/     	 ww+[9 	Dr   c                 ^    [         R                  " SS5      n[         R                  " U5        g)zTest adding a valid rule.r   r   Nr	   r   r   r   s     r   test_add_rule_with_valid_rule)TestAddRule.test_add_rule_with_valid_rule   s!    ww+[9 	Dr   c                 \    [         R                  " S5      n[         R                  " U5        g)z0Test adding a rule without a name (should work).r   Nr   r   s     r   $test_add_rule_with_rule_without_name0TestAddRule.test_add_rule_with_rule_without_name$       ww+, 	Dr   c                     [         R                  " S5      n[         R                  " S5      n[         R                  " U5        [         R                  " U5        g)z2Test adding multiple rules without explicit names.test1(x) <- fact1(x)test2(x) <- fact2(x)Nr   r   rule1rule2s      r   #test_add_multiple_rules_auto_naming/TestAddRule.test_add_multiple_rules_auto_naming+   s:    ././ 	E
Er   c                     [         R                  " SS5      n[         R                  " S5      n[         R                  " U5        [         R                  " U5        g)z$Test mixing named and unnamed rules.r&   
named_ruler'   Nr   r(   s      r   *test_add_rule_with_named_and_unnamed_rules6TestAddRule.test_add_rule_with_named_and_unnamed_rules4   s<    .=./ 	E
Er   c                     [         R                  " S5      n[         R                  " S5      n[         R                  " U5        [         R                  " U5        g)z-Test that add_rule works with multiple rules.r&   r'   Nr   r(   s      r   &test_add_rule_appends_to_existing_list2TestAddRule.test_add_rule_appends_to_existing_list=   s8    ././
E
Er    N)__name__
__module____qualname____firstlineno____doc__r   r   r   r"   r+   r/   r2   __static_attributes__r4   r   r   r   r   	   s(    #	r   r   c                   N    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rSrg)TestAddFactH   zTest add_fact() function.c                 X    [         R                  " 5         [         R                  " 5         gr   r   r   s    r   r   TestAddFact.setup_methodK   r   r   c                     [         R                  " 5         [         R                  " S5      n[         R                  " U5        g)z2Test add_fact() works when starting with no facts.test(node1)N)r	   r
   Factadd_factr   facts     r   %test_add_fact_creates_lists_when_none1TestAddFact.test_add_fact_creates_lists_when_noneQ   s)     	
ww}% 	Dr   c                 \    [         R                  " S5      n[         R                  " U5        g)zTest adding a node fact.rA   Nr	   rB   rC   rD   s     r   test_add_fact_node_fact#TestAddFact.test_add_fact_node_fact[   s    ww}% 	Dr   c                 \    [         R                  " S5      n[         R                  " U5        g)zTest adding an edge fact.ztest(node1, node2)NrI   rD   s     r   test_add_fact_edge_fact#TestAddFact.test_add_fact_edge_factb   r$   r   c                     [         R                  " SS5      n[         R                  " U5        UR                  S:X  d   eg)zTest adding a fact with a name.rA   
named_factN)r	   rB   rC   namerD   s     r   test_add_fact_with_name#TestAddFact.test_add_fact_with_namei   s0    ww}l3
DyyL(((r   c                     [         R                  " S5      n[         R                  " U5        UR                  R	                  S5      (       d   eg)z5Test adding a fact without a name auto-generates one.rA   fact_Nr	   rB   rC   rQ   
startswithrD   s     r   )test_add_fact_without_name_auto_generates5TestAddFact.test_add_fact_without_name_auto_generatesq   s9    ww}%
D yy##G,,,,r   c                 t   [         R                  " S5      n[         R                  " S5      n[         R                  " U5        [         R                  " U5        UR                  R	                  S5      (       d   eUR                  R	                  S5      (       d   eUR                  UR                  :w  d   eg)z,Test adding multiple facts with auto-naming.ztest1(node1)ztest2(node2)rU   NrV   )r   fact1fact2s      r   #test_add_multiple_facts_auto_naming/TestAddFact.test_add_multiple_facts_auto_namingz   s    ''
E
E zz$$W----zz$$W----zzUZZ'''r   c                 b    [         R                  " SSSS5      n[         R                  " U5        g)z$Test adding a fact with time bounds.rA   
timed_factr      NrI   rD   s     r   test_add_fact_with_time_bounds*TestAddFact.test_add_fact_with_time_bounds   s"    ww}lAq9
Dr   c                     [         R                  " S5      n[         R                  " S5      n[         R                  " U5        [         R                  " U5        g)z%Test adding both node and edge facts.ztest_node(node1)ztest_edge(node1, node2)NrI   )r   	node_fact	edge_facts      r   "test_add_mixed_node_and_edge_facts.TestAddFact.test_add_mixed_node_and_edge_facts   s8    GG./	GG56	
I
Ir   r4   N)r5   r6   r7   r8   r9   r   rF   rJ   rM   rR   rX   r]   rb   rg   r:   r4   r   r   r<   r<   H   s2    #)-(r   r<   c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
TestAddAnnotationFunction   z(Test add_annotation_function() function.c                 X    [         R                  " 5         [         R                  " 5         gr   r   r   s    r   r   &TestAddAnnotationFunction.setup_method   r   r   c                 6    S n[         R                  " U5        g)z(Test adding a valid annotation function.c                     gN)      ?rq   r4   annotationsweightss     r   	test_funcOTestAddAnnotationFunction.test_add_annotation_function_valid.<locals>.test_func       r   Nr	   add_annotation_function)r   ru   s     r   "test_add_annotation_function_valid<TestAddAnnotationFunction.test_add_annotation_function_valid   s    	 	""9-r   c                 6    S n[         R                  " U5        g)z)Test adding a lambda annotation function.c                     g)N)皙?r~   r4   rr   s     r   <lambda>OTestAddAnnotationFunction.test_add_annotation_function_lambda.<locals>.<lambda>   s    Jr   Nrx   )r   funcs     r   #test_add_annotation_function_lambda=TestAddAnnotationFunction.test_add_annotation_function_lambda   s    6
""4(r   c                     S nS nS n[         R                  " U5        [         R                  " U5        [         R                  " U5        g)z*Test adding multiple annotation functions.c                     g)N)皙?r   r4   rr   s     r   func1OTestAddAnnotationFunction.test_add_multiple_annotation_functions.<locals>.func1   rw   r   c                     g)N)皙?r   r4   rr   s     r   func2OTestAddAnnotationFunction.test_add_multiple_annotation_functions.<locals>.func2   rw   r   c                     g)N)333333?r   r4   rr   s     r   func3OTestAddAnnotationFunction.test_add_multiple_annotation_functions.<locals>.func3   rw   r   Nrx   )r   r   r   r   s       r   &test_add_multiple_annotation_functions@TestAddAnnotationFunction.test_add_multiple_annotation_functions   s=    			 	""5)
""5)
""5)r   c                 6    S n[         R                  " U5        g)z3Test adding annotation function with complex logic.c                 r    U (       d  g[        S [        X5       5       5      n[        S U  5       5      nX#4$ )N)        r   c              3   H   #    U  H  u  pXS    R                   -  v   M     g7fr   Nlower.0was      r   	<genexpr>rTestAddAnnotationFunction.test_add_annotation_function_with_complex_logic.<locals>.complex_func.<locals>.<genexpr>   s     M3L41aDJJ3L    "c              3   *   #    U  H	  oS    v   M     g7f)   Nr4   )r   r   s     r   r   r      s     7;aqT;s   )sumzipmin)rs   rt   total
confidences       r   complex_func_TestAddAnnotationFunction.test_add_annotation_function_with_complex_logic.<locals>.complex_func   s6    M3w3LMME7;77J$$r   Nrx   )r   r   s     r   /test_add_annotation_function_with_complex_logicITestAddAnnotationFunction.test_add_annotation_function_with_complex_logic   s    	% 	""<0r   r4   N)r5   r6   r7   r8   r9   r   rz   r   r   r   r:   r4   r   r   rj   rj      s    2.)* 
1r   rj   c                   *    \ rS rSrSrS rS rS rSrg)TestGetRules   zTest get_rules() function.c                 X    [         R                  " 5         [         R                  " 5         gr   r   r   s    r   r   TestGetRules.setup_method   r   r   c                 8    [         R                  " 5       nUb   eg)z/Test get_rules() when no rules have been added.N)r	   	get_rules)r   ruless     r   test_get_rules_when_none%TestGetRules.test_get_rules_when_none   s    }}r   c                     [         R                  " SS5      n[         R                  " SS5      n[         R                  " U5        [         R                  " U5        [         R                  " 5       nUc   eg)z%Test get_rules() returns added rules.r&   r)   r'   r*   N)r	   r   r   r   )r   r)   r*   r   s       r   !test_get_rules_after_adding_rules.TestGetRules.test_get_rules_after_adding_rules   sS    .8.8
E
E   r   r4   N)	r5   r6   r7   r8   r9   r   r   r   r:   r4   r   r   r   r      s    $
	!r   r   c                   0    \ rS rSrSrS rS rS rS rSr	g)	TestAddInconsistentPredicate   z+Test add_inconsistent_predicate() function.c                 X    [         R                  " 5         [         R                  " 5         gr   r   r   s    r   r   )TestAddInconsistentPredicate.setup_method   r   r   c                 2    [         R                  " SS5        g)z.Test adding a pair of inconsistent predicates.pred1pred2Nr	   add_inconsistent_predicater   s    r   $test_add_inconsistent_predicate_pairATestAddInconsistentPredicate.test_add_inconsistent_predicate_pair        	%%gw7r   c                     [         R                  " SS5        [         R                  " SS5        [         R                  " SS5        g)z6Test adding multiple pairs of inconsistent predicates.r   r   pred3pred4pred5pred6Nr   r   s    r   .test_add_multiple_inconsistent_predicate_pairsKTestAddInconsistentPredicate.test_add_multiple_inconsistent_predicate_pairs   s2    
%%gw7
%%gw7
%%gw7r   c                 2    [         R                  " SS5        g)z;Test adding the same predicate as inconsistent with itself.r   Nr   r   s    r   /test_add_inconsistent_predicate_same_predicatesLTestAddInconsistentPredicate.test_add_inconsistent_predicate_same_predicates   r   r   r4   N)
r5   r6   r7   r8   r9   r   r   r   r   r:   r4   r   r   r   r      s    58
88r   r   c                   0    \ rS rSrSrS rS rS rS rSr	g)	TestOperationSequences   z!Test sequences of add operations.c                 X    [         R                  " 5         [         R                  " 5         gr   r   r   s    r   r   #TestOperationSequences.setup_method  r   r   c                    [         R                  " S5      n[         R                  " S5      n[         R                  " U5        [         R                  " U5        [         R                  " S5      n[         R                  " S5      n[         R                  " U5        [         R                  " U5        S n[         R
                  " U5        [         R                  " SS5        g)	z(Test adding rules and facts in sequence.r&   r'   fact1(node1)fact2(node2)c                     grp   r4   rr   s     r   ru   KTestOperationSequences.test_add_rules_and_facts_sequence.<locals>.test_func  rw   r   r   r   N)r	   r   r   rB   rC   ry   r   )r   r)   r*   r[   r\   ru   s         r   !test_add_rules_and_facts_sequence8TestOperationSequences.test_add_rules_and_facts_sequence  s     ././
E
E ''
E
E	
""9- 	%%gw7r   c                    [         R                  " [         R                  " SS5      5        [         R                  " [         R                  " SS5      5        [         R
                  " SS5        S n[         R                  " U5        [         R                  " [         R                  " S5      5        [         R                  " [         R                  " S	5      5        g
)z&Test a complex sequence of operations.zrule1(x) <- fact1(x)r.   r   rP   test1test2c                 <    [        S [        X5       5       5      S4$ )Nc              3   H   #    U  H  u  pXS    R                   -  v   M     g7fr   r   r   s      r   r   bTestOperationSequences.test_complex_operation_sequence.<locals>.annotation_func.<locals>.<genexpr>&  s     L2K$!qQ4::~2Kr   g      ?)r   r   rr   s     r   annotation_funcOTestOperationSequences.test_complex_operation_sequence.<locals>.annotation_func%  s    L#g2KLLcQQr   zrule2(x) <- fact2(x)r   N)r	   r   r   rC   rB   r   ry   )r   r   s     r   test_complex_operation_sequence6TestOperationSequences.test_complex_operation_sequence  s     	BGG2LAB
BGGNL9:
%%gw7	R
""?3
BGG234
BGGN+,r   c                    [         R                  " [         R                  " S5      5        [         R                  " [         R                  " S5      5        [         R
                  " 5         [         R                  " 5         [         R                  " [         R                  " S5      5        [         R                  " [         R                  " S5      5        S n[         R                  " U5        g)z+Test operations work correctly after reset.r   fact(node1)znew_test(x) <- new_fact(x)znew_fact(node1)c                     g)N)ffffff?r   r4   rr   s     r   new_funcDTestOperationSequences.test_operations_after_reset.<locals>.new_func:  rw   r   N)r	   r   r   rC   rB   r
   r   ry   )r   r   s     r   test_operations_after_reset2TestOperationSequences.test_operations_after_reset,  s     	BGG012
BGGM*+ 	

 	BGG89:
BGG-./	
""8,r   r4   N)
r5   r6   r7   r8   r9   r   r   r   r   r:   r4   r   r   r   r      s    +8,--r   r   c                   0    \ rS rSrSrS rS rS rS rSr	g)	TestAutoNamingCountersi?  z"Test auto-naming counter behavior.c                 X    [         R                  " 5         [         R                  " 5         gr   r   r   s    r   r   #TestAutoNamingCounters.setup_methodB  r   r   c                    [         R                  " S5      n[         R                  " SS5      n[         R                  " S5      n[         R                  " U5        [         R                  " U5        [         R                  " U5        g)z3Test that multiple rules can be added successfully.r&   r'   r.   ztest3(x) <- fact3(x)Nr   )r   r)   r*   rule3s       r   test_rule_counter_persistence4TestAutoNamingCounters.test_rule_counter_persistenceH  sW    ./.=./ 	E
E
Er   c                     [         R                  " S5      n[         R                  " S5      n[         R                  " U5        [         R                  " U5        UR
                  R                  S5      (       d   eg)z5Test that rules and facts can be added independently.r   r   rU   N)r	   r   rB   r   rC   rQ   rW   )r   r   rE   s      r   test_fact_counter_independence5TestAutoNamingCounters.test_fact_counter_independenceS  sV    ww+,ww}% 	D
D yy##G,,,,r   c                    [         R                  " S5      n[         R                  " S5      n[         R                  " U5        [         R                  " U5        [         R
                  " 5         [         R                  " S5      n[         R                  " S5      n[         R                  " U5        [         R                  " U5        UR                  R                  S5      (       d   eg)z+Test that rules and facts work after reset.r&   r   r'   r   rU   N)r	   r   rB   r   rC   r   rQ   rW   )r   r)   r[   r*   r\   s        r   test_counters_after_reset0TestAutoNamingCounters.test_counters_after_reset_  s     ./'
E
E 	 ./'
E
E zz$$W----r   r4   N)
r5   r6   r7   r8   r9   r   r   r   r   r:   r4   r   r   r   r   ?  s    ,	
-.r   r   )r9   pytestpyreasonr	   r   r<   rj   r   r   r   r   r4   r   r   <module>r      s^   
  : :~K K\21 21j! !48 84=- =-@2. 2.r   