Bläddra i källkod

Update tests to use to_strings to verify.

Steve Thielemann 4 månader sedan
förälder
incheckning
f7142e9857
2 ändrade filer med 104 tillägg och 5 borttagningar
  1. 71 3
      sudoku/src/ksudoku.rs
  2. 33 2
      sudoku/src/sudoku.rs

+ 71 - 3
sudoku/src/ksudoku.rs

@@ -220,7 +220,21 @@ mod tests {
         assert!(load.is_ok());
         
         // Ok, puzzle is loaded!
-        board.display();
+        let strings = board.to_strings();
+        assert_eq!(
+            strings,
+            vec![
+                "  4   8  ",
+" 6  1  2 ",
+"3  9 5  6",
+"  72 16  ",
+" 3     9 ",
+"  18 35  ",
+"9  3 6  2",
+" 4  5  8 ",
+"  3   7  ",
+            ]
+        );
 
         let mut testfile = test_files_path();
         testfile.push("16-puzzle");
@@ -237,7 +251,29 @@ mod tests {
         assert!(load.is_ok());
         
         // Ok, puzzle is loaded!
-        board.display();
+        let strings: Vec<String> = board.to_strings();
+        assert_eq!(
+            strings,
+            vec![
+                " D    O    C  IN",
+                "A  ENC   IL     ",
+                "NG  AP   J MHC  ",
+                "  P H   D A  FOL",
+                "IOHKFB  A   L  P",
+                " BN  M E L ID   ",
+                "LE  O AN K BC   ",
+                " C    H    JO EF",
+                "EN GP    A    F ",
+                "   OG J IM L  NC",
+                "   MK B C N  PG ",
+                "C  L   F  PEMIKO",
+                "OPC  N H   F J  ",
+                "  EHJ I   MA  CK",
+                "     FM   IPA  D",
+                "FM  L    H    P "                
+            ]
+        );
+        // board.display();
         
         let mut testfile = test_files_path();
         testfile.push("25-puzzle");
@@ -254,7 +290,39 @@ mod tests {
         assert!(load.is_ok());
         
         // Ok, puzzle is loaded!
-        board.display();
+        // board.display();
+        let strings: Vec<String> = board.to_strings();
+        assert_eq!(
+            strings, 
+            vec![
+                " T DPF    Y H R    WSX L ",
+                "L QF     J X C G     UB D",
+                " CK S LNRP  G  UTQO H MA ",
+                "JG   H S XELDUPM F B   RT",
+                "Y N RQ UCDOK AISJL HP G E",
+                "F  OA N UK VQI HY B DT  C",
+                "  S  A C VUE GJQ N I  R  ",
+                "  CPD JGMIA   OELSU VBK  ",
+                "  G LE D BHT XMW K PI Y  ",
+                " EXIBOWFLY     VAMTJUGQS ",
+                "G  HV TMI       EWF BR  O",
+                " A JFUK W  P D  M GLXE N ",
+                "R LN G             O QI F",
+                " S TCYP B  H O  X JNAK M ",
+                "M  XK ALJ       UHQ GP  Y",
+                " VTRYBSEFM     KWOICJNLG ",
+                "  U XD J WCN RTA E QY P  ",
+                "  HQN COVTJ   EBGDL WSF  ",
+                "  F  X Y LWB SVJ R T  O  ",
+                "E  CJ R AN GOF XH V MD  B",
+                "S V OI ANHDC TGLQJ YF X P",
+                "CX   L K RFUYBWO V A   DQ",
+                " FR H DQOC  K  INBW T UY ",
+                "T JL     G I P F     OC W",
+                " B KMV    Q J H    GRI E "
+        
+            ]
+        );        
 
     }
 }

+ 33 - 2
sudoku/src/sudoku.rs

@@ -1003,8 +1003,39 @@ mod tests {
         let mut board: AnyBoard = AnyBoard::new(5);
         let result = board.load_from_tld('b', '_', "_m_kzg____h_s_n____ftd_u_u_dh_____f_b_t_w_____yg_c_rl_o_tdhy__m__uvig_w_sk_eg___p_q_jikouys_r_d___mlq_t_sb_emcwg_dlzyo_kp_i_ng__ir_b_fp_vhz_ce_y_jm__w__m__o_k_xul_qbt_d_s__e____otv_dhegn___mfkpz_blr____s_dv_n_mjx_ckg_w_bo_p___kqyelwjcz_____nxumoisdh_z__fp_vbi_______dkx_eg__r_y_mlwf_u__q_i__o_chdv_j_i_he_r_____________p_zl_k_d_vbjh_y__e_p__s_tguc_q_s__qj_kpn_______ufw_hx__i_hvntirfxw_____lbckympjg___u_kz_m_bfn_yvx_h_ir_o____rgm_otlnx___ipfes_kwc____p__c_v_ugh_krj_m_w__x__x__ci_j_qk_mpo_dr_u_zb__ht_i_qe_wjvcy_bhkzx_ng_u_syv___u_c_hsfrlqo_t_e___pj_cn_h_slzr__j__mqgp_y_vd_m_bs_____t_o_n_h_____ez_f_e_ufd____p_g_z____cqr_x_");
         assert!(result.is_ok());
-        board.display();
-
+        // board.display();
+        let strings: Vec<String> = board.to_strings();
+        assert_eq!(
+            strings, 
+            vec![
+                " T DPF    Y H R    WSX L ",
+                "L QF     J X C G     UB D",
+                " CK S LNRP  G  UTQO H MA ",
+                "JG   H S XELDUPM F B   RT",
+                "Y N RQ UCDOK AISJL HP G E",
+                "F  OA N UK VQI HY B DT  C",
+                "  S  A C VUE GJQ N I  R  ",
+                "  CPD JGMIA   OELSU VBK  ",
+                "  G LE D BHT XMW K PI Y  ",
+                " EXIBOWFLY     VAMTJUGQS ",
+                "G  HV TMI       EWF BR  O",
+                " A JFUK W  P D  M GLXE N ",
+                "R LN G             O QI F",
+                " S TCYP B  H O  X JNAK M ",
+                "M  XK ALJ       UHQ GP  Y",
+                " VTRYBSEFM     KWOICJNLG ",
+                "  U XD J WCN RTA E QY P  ",
+                "  HQN COVTJ   EBGDL WSF  ",
+                "  F  X Y LWB SVJ R T  O  ",
+                "E  CJ R AN GOF XH V MD  B",
+                "S V OI ANHDC TGLQJ YF X P",
+                "CX   L K RFUYBWO V A   DQ",
+                " FR H DQOC  K  INBW T UY ",
+                "T JL     G I P F     OC W",
+                " B KMV    Q J H    GRI E "
+        
+            ]
+        );
         let mut solver = AnySolver::new_from(&board);
         assert!(solver.validate_board());
     }