
    ni0                     l   S SK rS SKrS r\R                  R
                  \R                  R                  S/ SQ5      S 5       5       r\R                  R                  SSS/5      S 5       r\R                  R                  S/ SQ5      S	 5       r	\R                  R                  S/ SQ5      S
 5       r
g)    Nc                    [         R                  " 5         [         R                  " 5         [         R                  " 5         S[         R                  l        U S:X  a  S[         R                  l        gU S:X  a  S[         R                  l        gg)z3Configure PyReason settings for the specified mode.TfpparallelN)prresetreset_rulesreset_settingssettingsverbose
fp_versionparallel_computing)modes    _/home/james-whalen/.local/lib/python3.13/site-packages/tests/functional/test_basic_reasoning.py
setup_moder      sY    HHJNNBKKt|!%		)-& 
    r   )regularr   r   c                 t   [        U 5        SnS[        R                  l        [        R                  " U5        [        R
                  " [        R                  " SS5      5        [        R                  " [        R                  " SSSS5      5        [        R                  " SS	9n[        R                  " US
/5      n[        U5       H(  u  pE[        SU 35        [        U5        [        5         M*     [        US   5      S:X  d   S5       e[        US   5      S:X  d   S5       e[        US   5      S:X  d   S5       eSUS   S   R                  ;   a"  US   R                  S   R                   SS/:X  d   S5       eSUS   S   R                  ;   a"  US   R                  S   R                   SS/:X  d   S5       eSUS   S   R                  ;   a"  US   R                  S   R                   SS/:X  d   S5       eSUS   S   R                  ;   a"  US   R                  S   R                   SS/:X  d   S5       eSUS   S   R                  ;   a"  US   R                  S   R                   SS/:X  d   S5       eSUS   S   R                  ;   a"  US   R                  S   R                   SS/:X  d   S5       eg)z>Test basic hello world program with different reasoning modes.(./tests/functional/friends_graph.graphmlTz=popular(x) <-1 popular(y), Friends(x,y), owns(y,z), owns(x,z)popular_rulepopular(Mary)popular_factr      	timestepspopularTIMESTEP -    )At t=0 there should be one popular person)At t=1 there should be two popular people   +At t=2 there should be three popular peopleMary	component7Mary should have popular bounds [1,1] for t=0 timesteps7Mary should have popular bounds [1,1] for t=1 timesteps7Mary should have popular bounds [1,1] for t=2 timestepsJustin9Justin should have popular bounds [1,1] for t=1 timesteps9Justin should have popular bounds [1,1] for t=2 timestepsJohn7John should have popular bounds [1,1] for t=2 timestepsN)r   r   r
   
atom_traceload_graphmladd_ruleRuleadd_factFactreasonfilter_and_sort_nodes	enumerateprintlenvaluesilocr   )r   
graph_pathinterpretation
dataframestdfs         r   test_hello_worldr>      s    t <J "BKK OOJKKWYghiKKA>? YY+N )).9+FJ:&A3 b	 '
 z!}"O$OO"z!}"O$OO"z!}"Q$QQ" Z];/666:a=;M;Ma;P;X;X]^`a\b;b  ^  e^  ^bZ];/666:a=;M;Ma;P;X;X]^`a\b;b  ^  e^  ^bZ];/666:a=;M;Ma;P;X;X]^`a\b;b  ^  e^  ^b z!}[1888Z]=O=OPQ=R=Z=Z_`bc^d=d  b  gb  bdz!}[1888Z]=O=OPQ=R=Z=Z_`bc^d=d  b  gb  bd Z];/666:a=;M;Ma;P;X;X]^`a\b;b  ^  e^  ^b;br   r   r   c                 t   [        U 5        SnS[        R                  l        [        R                  " U5        [        R
                  " [        R                  " SS5      5        [        R                  " [        R                  " SSSS5      5        [        R                  " SS	9n[        R                  " US
/5      n[        U5       H(  u  pE[        SU 35        [        U5        [        5         M*     [        US   5      S:X  d   S5       e[        US   5      S:X  d   S5       e[        US   5      S:X  d   S5       eSUS   S   R                  ;   a"  US   R                  S   R                   SS/:X  d   S5       eSUS   S   R                  ;   a"  US   R                  S   R                   SS/:X  d   S5       eSUS   S   R                  ;   a"  US   R                  S   R                   SS/:X  d   S5       eSUS   S   R                  ;   a"  US   R                  S   R                   SS/:X  d   S5       eSUS   S   R                  ;   a"  US   R                  S   R                   SS/:X  d   S5       eSUS   S   R                  ;   a"  US   R                  S   R                   SS/:X  d   S5       e[        R"                  " U5      u  pgU S:X  aG  XfS   S:H  US   S:H  -     n[        U5      S:  d   S5       eUR                  S   n	U	S   S   S :X  d   eg!UR                  S   S   S   S :X  d   eg!)"z%Test clause reordering functionality.r   Tz=popular(x) <-1 Friends(x,y), popular(y), owns(y,z), owns(x,z)r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r   NodezOccurred Due Toz*Should have at least one Justin rule entryzClause-1)r'   r"   N)r   r   r
   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r   get_rule_trace)
r   r9   r:   r;   r<   r=   rule_trace_node_justin_rule_rowsfirst_justin_rules
             r   test_reorder_clausesrF   >   s    t <J "BKK OOJKKWYghiKKA>? YY+N )).9+FJ:&A3 b	 '
 z!}"O$OO"z!}"O$OO"z!}"Q$QQ" Z];/666:a=;M;Ma;P;X;X]^`a\b;b  ^  e^  ^bZ];/666:a=;M;Ma;P;X;X]^`a\b;b  ^  e^  ^bZ];/666:a=;M;Ma;P;X;X]^`a\b;b  ^  e^  ^b z!}[1888Z]=O=OPQ=R=Z=Z_`bc^d=d  b  gb  bdz!}[1888Z]=O=OPQ=R=Z=Z_`bc^d=d  b  gb  bd Z];/666:a=;M;Ma;P;X;X]^`a\b;b  ^  e^  ^b **>:Ot|*F,Cx,OTcduTv  {I  UI  ,J  K#$q(V*VV(,11!4 ,Q/3EEEE ##A&z2159KKKKr   c                    [        U 5        S[        R                  l        SSKnUR                  5       nUR                  S5        UR                  S5        UR                  S5        UR                  S5        [        R                  " U5        [        R                  " [        R                  " SS	SS
5      5        [        R                  " [        R                  " SSSS
5      5        [        R                  " [        R                  " SSSS
5      5        [        R                  " [        R                  " SSSS
5      5        [        R                  " [        R                  " SS5      5        [        R                  " S
S9n[        R                  " US/SSS9nUS   n[        U5      S:X  d   S5       e[        [        U5      5       Vs/ s H  oeR                   U   S   S   PM     nn[        [        U5      S
-
  5       H  nXv   XvS
-      :  a  M   SU 35       e   [        R                  " US/SSS9nUS   n[        [        U5      5       Vs/ s H  oeR                   U   S   S   PM     nn[        [        U5      S
-
  5       H  nXv   XvS
-      ::  a  M   SU 35       e   [        R                  " US/SSS9nUS   n[        [        U5      5       Vs/ s H  oeR                   U   S   S
   PM     nn[        [        U5      S
-
  5       H  nX   XS
-      :  a  M   SU 35       e   [        R                  " US/SSS9nUS   n[        [        U5      5       Vs/ s H  oeR                   U   S   S
   PM     nn[        [        U5      S
-
  5       H  nX   XS
-      ::  a  M   SU 35       e   gs  snf s  snf s  snf s  snf )zUTest that filter_and_sort_nodes actually sorts nodes correctly by different criteria.Tr   NABCDzscore(A) : [0.7, 0.9]fact_ar   zscore(B) : [0.1, 0.2]fact_bzscore(C) : [0.4, 0.6]fact_czscore(D) : [0.2, 0.8]fact_dzresult(x) <- score(x)	test_ruler   scorelowersort_by
descending   zShould have 4 nodes#Lower bounds should be descending: F"Lower bounds should be ascending: upper#Upper bounds should be descending: "Upper bounds should be ascending: )r   r   r
   store_interpretation_changesnetworkxDiGraphadd_node
load_graphr0   r1   r.   r/   r2   r3   r6   ranger8   	r   nxgraphr:   resultr=   ilower_boundsupper_boundss	            r   /test_filter_and_sort_nodes_sorting_verificationri   v   sl    t/3BKK, JJLE	NN3	NN3	NN3	NN3MM% KK/1a@AKK/1a@AKK/1a@AKK/1a@A KK/=> YY+N %%nwi]abF	Br7a<...< 5:#b'NCNqGGAJw'*NLC3|$q(),s"33i7Z[gZh5ii3 *
 %%nwi]bcF	B49#b'NCNqGGAJw'*NLC3|$q(),s"33h7YZfYg5hh3 *
 %%nwi]abF	B49#b'NCNqGGAJw'*NLC3|$q(),s"33i7Z[gZh5ii3 *
 %%nwi]bcF	B49#b'NCNqGGAJw'*NLC3|$q(),s"33h7YZfYg5hh3 *; D D D Ds   N9N>O#Oc                    [        U 5        S[        R                  l        SSKnUR                  5       nUR                  SS5        UR                  SS5        UR                  SS5        UR                  SS5        [        R                  " U5        [        R                  " [        R                  " S	S
SS5      5        [        R                  " [        R                  " SSSS5      5        [        R                  " [        R                  " SSSS5      5        [        R                  " [        R                  " SSSS5      5        [        R                  " [        R                  " SS5      5        [        R                  " SS9n[        R                  " US/SSS9nUS   n[        U5      S:X  d   S5       e[        [        U5      5       Vs/ s H  oeR                   U   S   S   PM     nn[        [        U5      S-
  5       H  nXv   XvS-      :  a  M   SU 35       e   [        R                  " US/SSS9nUS   n[        [        U5      5       Vs/ s H  oeR                   U   S   S   PM     nn[        [        U5      S-
  5       H  nXv   XvS-      ::  a  M   SU 35       e   [        R                  " US/SSS9nUS   n[        [        U5      5       Vs/ s H  oeR                   U   S   S   PM     nn[        [        U5      S-
  5       H  nX   XS-      :  a  M   SU 35       e   [        R                  " US/SSS9nUS   n[        [        U5      5       Vs/ s H  oeR                   U   S   S   PM     nn[        [        U5      S-
  5       H  nX   XS-      ::  a  M   SU 35       e   gs  snf s  snf s  snf s  snf ) zUTest that filter_and_sort_edges actually sorts edges correctly by different criteria.Tr   NrH   rI   rJ   rK   Ezweight(A, B) : [0.7, 0.9]fact_abr   zweight(B, C) : [0.1, 0.2]fact_bczweight(C, D) : [0.4, 0.6]fact_cdzweight(D, E) : [0.2, 0.8]fact_dezresult(x, y) <- weight(x, y)rP   r   weightrR   rS   rV   zShould have 4 edgesrW   FrX   rY   rZ   r[   )r   r   r
   r\   r]   r^   add_edger`   r0   r1   r.   r/   r2   filter_and_sort_edgesr6   ra   r8   rb   s	            r   /test_filter_and_sort_edges_sorting_verificationrs      st    t/3BKK, JJLE	NN3	NN3	NN3	NN3MM% KK3Y1EFKK3Y1EFKK3Y1EFKK3Y1EF KK6DE YY+N %%nxj'^bcF	Br7a<...< 6;3r7^D^GGAJx(+^LD3|$q(),s"33i7Z[gZh5ii3 *
 %%nxj'^cdF	B5:3r7^D^GGAJx(+^LD3|$q(),s"33h7YZfYg5hh3 *
 %%nxj'^bcF	B5:3r7^D^GGAJx(+^LD3|$q(),s"33i7Z[gZh5ii3 *
 %%nxj'^cdF	B5:3r7^D^GGAJx(+^LD3|$q(),s"33h7YZfYg5hh3 *; E E E Es   N=OO'O)pyreasonr   pytestr   markslowparametrizer>   rF   ri   rs    r   r   <module>rz      s     
. !>?'^ @ '^R )T!234L 44Ln !>?Ei @EiP !>?Ei @Eir   