zoukankan      html  css  js  c++  java
  • 软件工程——数独 测试2

    数独检查模块测试

    GoogleTest代码

    #include "pch.h"
    #include "share.h"
    
    using namespace std;
    
    namespace TestSudokuChecker
    {
        int test_sudoku[10][10] =
        {
            0, 0, 0, 0, 0, 0, 0, 0, 0,0,
            0,2, 6, 8 ,4, 7 ,3 ,9, 5 ,1,
            0,3 ,4 ,1 ,9 ,6 ,5 ,2 ,7 ,8,
            0,7 ,9, 5 ,8 ,1 ,2 ,3 ,6 ,4,
            0,5 ,7 ,4 ,6 ,2 ,1 ,8 ,3 ,9,
            0,1 ,3 ,9, 5 ,4 ,8 ,6 ,2 ,7,
            0,8 ,2 ,6 ,3 ,9 ,7 ,4 ,1 ,5,
            0,9 ,1 ,7, 2, 8 ,6 ,5 ,4 ,3,
            0,6 ,8 ,3, 1 ,5 ,4 ,7 ,9 ,2,
            0,4, 5 ,2, 7 ,3, 9, 1 ,8, 6,
        };
    
        TEST(SudokuChecker_Test, Grid)
        {
            int** s = new int* [N_ROW_SUDOKU];
    
            s[0] = new int[10];
            for (int i = 0; i < 10; i++)
            {
                s[i] = new int[10];
                for (int j = 0; j < 10; j++)
                    s[i][j] = test_sudoku[i][j];
            }
    
            EXPECT_EQ(checkGrid(s), 0);
    
            s[1][3] = 4;
            EXPECT_EQ(checkGrid(s), 22); 
    
            s[1][3] = 8;//复原
            s[1][1] = 8;
            EXPECT_EQ(checkGrid(s), 13); 
    
            s[1][1] = 2;
            s[5][6] = 3;
            EXPECT_EQ(checkGrid(s), 64); 
    
            for (int j = 0; j < 10; j++)
                delete[] s[j];
            delete[] s;
        }
    
        TEST(SudokuChecker_Test, RowCol)
        {
            int** s = new int* [N_ROW_SUDOKU];
    
            s[0] = new int[10];
            for (int i = 0; i < 10; i++)
            {
                s[i] = new int[10];
                for (int j = 0; j < 10; j++)
                    s[i][j] = test_sudoku[i][j];
            }
    
            EXPECT_EQ(checkRowCol(s), 0);
    
            s[1][3] = 4;
            EXPECT_EQ(checkRowCol(s), 14); 
    
            s[1][3] = 8;//复原
            s[1][1] = 8;
            EXPECT_EQ(checkRowCol(s), 13); 
    
            s[1][1] = 2;
            s[5][6] = 3;
            EXPECT_EQ(checkRowCol(s), 56); 
    
            for (int j = 0; j < 10; j++)
                delete[] s[j];
            delete[] s;
        }
    
        TEST(SudokuChecker_Test, All)
        {
            int** s = new int* [N_ROW_SUDOKU];
    
            s[0] = new int[10];
            for (int i = 0; i < 10; i++)
            {
                s[i] = new int[10];
                for (int j = 0; j < 10; j++)
                    s[i][j] = test_sudoku[i][j];
            }
    
            EXPECT_EQ(checkSudoku(s), 0);
    
            s[1][3] = 4;
            EXPECT_EQ(checkSudoku(s), -22); 
    
            s[1][3] = 8;//复原
            s[1][1] = 8;
            EXPECT_EQ(checkSudoku(s), -13); 
    
            s[1][1] = 2;
            s[5][6] = 3;
            EXPECT_EQ(checkSudoku(s), -64); 
    
            for (int j = 0; j < 10; j++)
                delete[] s[j];
            delete[] s;
        }
    }
    View Code

  • 相关阅读:
    Qt自定义一个事件类型
    Qt正则表达式限制输入
    QtQuick随笔
    右值引用示例
    虚函数习题复习
    实现基于IOCP的回声服务器端
    以纯重叠I/O方式实现回声服务器端(windows)
    使用事件对象(重叠I/O)
    pipe mmap
    ubuntu下压缩和解压缩的命令用法
  • 原文地址:https://www.cnblogs.com/harrypotterjackson/p/12201504.html
Copyright © 2011-2022 走看看