
    P1il1                         d Z ddlZddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ dd	lmZmZ ddlZ G d
 de      Zedk(  r ej(                          yy)zz
Test cases for LiuYao prompt preparation.
Tests the prompt generation without sending to LLM to verify content accuracy.
    N)datetime)TestCase)timezone)liuyao)prepare_liuyao_prompt)PromptTemplate)r   bzc                       e Zd ZdZd ZddZd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)LiuYaoPromptTestCasez)Test cases for LiuYao prompt preparation.c                 f    d| _         t        j                  j                  dddddd      | _        y)zSet up test fixtures.NTest LiuYao Templater   u   所问问题：{{question}}
占卜时间：{{qdate}}

六爻计算结果：
{{hexagram_calculation}}

动爻：{{changing_lines}}
动爻数量：{{changing_lines_count}}

变卦：{{changed_hexagram_info}}
变卦序：{{changed_hexagram_number}}activezzh-hans)namedivination_typecontentstatus
created_bylanguage)maxDiffr   objectscreatetest_templateselfs    =/home/cursorai/projects/iching/ai/tests/test_liuyao_prompt.pysetUpzLiuYaoPromptTestCase.setUp   s?     ,33::'$
+ ! ; 
    c	                 f   d|v rt        j                  |d      }	nt        j                  |d      }	t        j                  |	      }	t	        j
                  |	j                  |	j                  |	j                  |	j                  |	j                        }
|	j                  d      |
d<   t	        j                  |
d   d   |
d   d         |
d<   t        j                  |
d   d         }t        j                  t!        |      t!        |      t!        |      t!        |      t!        |      t!        |            }t        j"                  ||
      }|
|||d	}t$        j&                  j)                  |	|t!        |      t!        |      t!        |      t!        |      t!        |      t!        |      |
	      }|S )zBHelper method to create a LiuYao object with specified parameters./z%Y/%m/%d %H:%M:%Sz%Y-%m-%d %H:%M:%Sdatedaygeempty)r	   god6lyrel)	qdatequestiony1y2y3y4y5y6data)r   strptimer   
make_awarebazigetDateTimeGodEarthStemyearmonthr!   hourminutestrftimecalcEarthEmptyliuyao_utilcalc6Godcalc6YaostrcalcRelationshipr   r   r   )r   date_strr*   r+   r,   r-   r.   r/   r)   date_objr	   r%   r&   r'   gua_data
liuyao_objs                   r   create_liuyao_objectz)LiuYaoPromptTestCase.create_liuyao_object,   sz    (?((3FGH((3FGH &&x0 ))MM8>>8<<MM8??
 &&':;6
))"U)C."U)C.I7##BuIcN3!!#b'3r7CGSWc"gsSUwW**2r2
 	
 ^^**2w2w2w2w2w2w + 


 r   c           	          | j                  ddddddd      }t        |      }| j                  d|       | j                  d|       y)uG   Test 1: LiuYao without moving lines should not have '动爻' in prompt.2025-02-03 12:00:00r   r*   r+   r,   r-   r.   r/   	   无动爻u   动爻数量：0NrD   r   assertInr   rC   prompts      r   test_no_moving_lines_no_dongyaz3LiuYaoPromptTestCase.test_no_moving_lines_no_dongya[   sT     ..!Q1qQ / 


 'z2 	k6*(&1r   c           	          | j                  ddddddd      }t        |      }| j                  d|       | j                  d|       y)zATest 2: LiuYao without moving lines should not have changing gua.rF      rG   u
   变卦：
u   变卦序：NrI   rK   s      r   $test_no_moving_lines_no_changing_guaz9LiuYaoPromptTestCase.test_no_moving_lines_no_changing_guai   sQ    ..!Q1qQ / 


 'z2 	mV,nf-r   c           	          | j                  ddddddd      }t        |      }| j                  d|       | j                  d|       y)u@   Test 3: LiuYao with moving lines should have '动爻' in prompt.rF   r   o   rG      动爻数量：1rH   NrD   r   rJ   assertNotInrK   s      r   !test_with_moving_lines_has_dongyaz6LiuYaoPromptTestCase.test_with_moving_lines_has_dongyav   T    ..!Q1q / 


 'z2 	(&1f-r   c           	      n    | j                  ddddddd      }t        |      }| j                  d|       y)z:Test 4: LiuYao with moving lines should have changing gua.rF   r   rR   rG   u   变卦：
变卦序：
NrD   r   rU   rK   s      r   'test_with_moving_lines_has_changing_guaz<LiuYaoPromptTestCase.test_with_moving_lines_has_changing_gua   sF    ..!Q1q / 


 'z2 	4f=r   c           	          | j                  ddddddd      }t        |      }| j                  d|       | j                  d|       | j                  d|       | j                  d|       | j                  d|       y	)
z>Test 5: Bazi date for 3rd Feb 2025 22:11:00 should be correct.z2025-02-03 22:11:00r   rG   	   乙巳年u	   戊寅月	   癸卯日	   癸亥时   空亡：辰巳NrI   rK   s      r   test_bazi_date_2025_02_03_22_11z4LiuYaoPromptTestCase.test_bazi_date_2025_02_03_22_11   |    ..!Q1qQ / 


 'z2 	k6*k6*k6*k6*'0r   c           	          | j                  ddddddd      }t        |      }| j                  d|       | j                  d|       | j                  d|       | j                  d|       | j                  d|       y	)
z>Test 6: Bazi date for 3rd Feb 2025 22:10:00 should be correct.z2025-02-03 22:10:00r   rG   u	   甲辰年u	   丁丑月r]   r^   r_   NrI   rK   s      r   test_bazi_date_2025_02_03_22_10z4LiuYaoPromptTestCase.test_bazi_date_2025_02_03_22_10   ra   r   c           	          | j                  ddddddd      }t        |      }| j                  d|       | j                  d|       y)	uO   Test 7: When hidden moving line is also moving line, no '暗动' should appear.2025/02/12 12:00:00r   rR   rO   rG   rS   rH   NrT   rK   s      r   *test_hidden_moving_vs_moving_line_priorityz?LiuYaoPromptTestCase.test_hidden_moving_vs_moving_line_priority   rW   r   c           	      n    | j                  ddddddd      }t        |      }| j                  d|       y)u@   Test 8: Test presence of hidden moving line (暗动) at 4th yao.re   r   rO   rG   u   暗动NrI   rK   s      r   test_hidden_moving_line_andongz3LiuYaoPromptTestCase.test_hidden_moving_line_andong   C    ..!Q1qQ / 


 'z2 	h'r   c           	      n    | j                  ddddddd      }t        |      }| j                  d|       y)u,   Test 9: No hidden 6qin (伏神) in main gua.re   rO   r   rG   u   伏神NrY   rK   s      r   test_no_hidden_6qin_fushenz/LiuYaoPromptTestCase.test_no_hidden_6qin_fushen   sE    ..!Q1qQ / 


 'z2 	6*r   c           	      n    | j                  ddddddd      }t        |      }| j                  d|       y)u7   Test 10: Hidden 6qin (伏神) case 1 - 3rd and 5th yao.re   rO   r   rG   u   伏神：辛酉，官鬼NrI   rK   s      r   test_hidden_6qin_fushen_case1z2LiuYaoPromptTestCase.test_hidden_6qin_fushen_case1   D    ..!Q1qQ / 


 'z2 	0&9r   c           	      n    | j                  ddddddd      }t        |      }| j                  d|       y)u/   Test 11: Hidden 6qin (伏神) case 2 - 2nd yao.re   rO   r   rG   u   伏神：乙巳，父母NrI   rK   s      r   test_hidden_6qin_fushen_case2z2LiuYaoPromptTestCase.test_hidden_6qin_fushen_case2   rn   r   c           	      n    | j                  ddddddd      }t        |      }| j                  d|       y)u(   Test 12: Test 六冲 gua identification.2023/08/16 12:00:00rO   r   rG   u   六冲NrI   rK   s      r   test_liuchong_guaz&LiuYaoPromptTestCase.test_liuchong_gua   ri   r   c           	      n    | j                  ddddddd      }t        |      }| j                  d|       y)u(   Test 13: Test 六合 gua identification.rr   r   rO   rG   u   六合NrI   rK   s      r   test_liuhe_guaz#LiuYaoPromptTestCase.test_liuhe_gua   ri   r   c           	      n    | j                  ddddddd      }t        |      }| j                  d|       y)u(   Test 14: Test 游魂 gua identification.rr   r   rO   rG   u   游魂NrI   rK   s      r   test_youhun_guaz$LiuYaoPromptTestCase.test_youhun_gua  ri   r   c           	      n    | j                  ddddddd      }t        |      }| j                  d|       y)u(   Test 15: Test 归魂 gua identification.rr   rO   r   rG   u   归魂NrI   rK   s      r   test_guihun_guaz$LiuYaoPromptTestCase.test_guihun_gua  ri   r   c           	          | j                  ddddddd      }t        |      | j                  d       | j                  d       | j                  d       | j                  t	        fdd	D                     y
)z@Test that the prompt contains all necessary structural elements.rF   r   rR   rG   u   问题u   本卦   测试问题c              3   &   K   | ]  }|v  
 y wN .0xrL   s     r   	<genexpr>zJLiuYaoPromptTestCase.test_prompt_structure_completeness.<locals>.<genexpr>.  s     N1MAAK1M   )2025u   二月u   三日N)rD   r   rJ   
assertTrueanyrK   s     @r   "test_prompt_structure_completenessz7LiuYaoPromptTestCase.test_prompt_structure_completeness  sz    ..!Q1q / 


 'z2 	h'h'nf- 	N1MNNOr   c           	          | j                  ddddddd      }t        |      | j                  t        fddD                     y)z<Test that yao positions are correctly represented in prompt.rF   rO   r   rG   c              3   &   K   | ]  }|v  
 y wr}   r~   r   s     r   r   zALiuYaoPromptTestCase.test_prompt_yao_positions.<locals>.<genexpr>:  s     n1mAAK1mr   )u   初爻u   二爻u   三爻u   四爻u   五爻u   上爻N)rD   r   r   r   rK   s     @r   test_prompt_yao_positionsz.LiuYaoPromptTestCase.test_prompt_yao_positions0  sN    ..!Q1qQ / 


 'z2 	n1mnnor   c           	          | j                  ddddddd      }t        |      }| j                  d|       | j                  d|       | j                  d|       | j                  d|       | j                  d|       y	)
zCTest for 23rd May 2025 15:05:42 should show correct empty branches.z2025-05-23 15:05:42r   rG   r\   u	   辛巳月u	   壬辰日u	   戊申时u   空亡：午未NrI   rK   s      r   test_bazi_date_2025_05_23_15_05z4LiuYaoPromptTestCase.test_bazi_date_2025_05_23_15_05<  ra   r   c                     t         j                  j                         j                          t        j                  j                  dd      j                          y)zClean up after tests.r   r   )r   r   N)r   r   alldeleter   filterr   s    r   tearDownzLiuYaoPromptTestCase.tearDownL  s@     	##%%%hE[%\ccer   N)r{   )__name__
__module____qualname____doc__r   rD   rM   rP   rV   rZ   r`   rc   rf   rh   rk   rm   rp   rs   ru   rw   ry   r   r   r   r   r~   r   r   r   r      sr    3
0-^2..>1 1 .
(
+::
(
(
(
(P"
p1 fr   r   __main__)r   unittestr   django.testr   django.utilsr   liuyao.modelsr   ai.utils.liuyao_analysisr   	ai.modelsr   iching.utilsr;   r	   r3   jsonr   r   mainr~   r   r   <module>r      sR   
     !   : $ : f8 fD
 zHMMO r   