Browse Source

unit test

nas 3 years ago
parent
commit
8d51f8d9d4
3 changed files with 85 additions and 0 deletions
  1. 17
    0
      include/Test.h
  2. 39
    0
      main_debug.cpp
  3. 29
    0
      src/Test.cpp

+ 17
- 0
include/Test.h View File

@@ -0,0 +1,17 @@
1
+#ifndef Test_H
2
+#define Test_H
3
+
4
+#include <iostream>
5
+
6
+class Test {
7
+ public :
8
+  Test( bool verbose );
9
+  static bool assertEqual( std::string result, std::string expectation );
10
+  static bool assertNotEqual( std::string result, std::string expectation );
11
+
12
+ private :
13
+  bool verbose;
14
+  
15
+};
16
+
17
+#endif

+ 39
- 0
main_debug.cpp View File

@@ -0,0 +1,39 @@
1
+#include <iostream>
2
+#include <string>
3
+#include "include/Crypt.h"
4
+#include "include/Test.h"
5
+
6
+char START = START;
7
+char END = END;
8
+
9
+/**
10
+ @brief Take a string on command line argument to encrypt it. For vigenere encnyption, the text is encrypted with itself as a key
11
+ **/
12
+int main( int argc, char* argv[]  )
13
+{
14
+    std::string txt = argv[1] ;
15
+
16
+  if( argc < 1 ){
17
+    std::cout << "Missing argument : need sentance to encrypt" << std::endl;
18
+    return 0;
19
+  }
20
+  if( argc > 1 ){
21
+    START = argv[2][0] ;
22
+  }
23
+  if( argc > 2 ){
24
+    END = argv[3][0] ;
25
+  }
26
+
27
+  std::string test_1 = "la mer à boire" ;
28
+  std::string test_2 = "xyzabc" ;
29
+  
30
+  Test::assertEqual( Crypt::cesar( test_1, 3, START, END ), "od phu à erluh") ;
31
+  Test::assertEqual( Crypt::vigenere( test_1, test_1, START, END ), "xb zjj à ddrjj") ;
32
+  Test::assertEqual( Crypt::atbash( test_1, START, END ), "oz nvi à ylriv") ;
33
+
34
+  Test::assertEqual( Crypt::cesar( test_2, 3, START, END ), "abcdef") ;
35
+  Test::assertEqual( Crypt::vigenere( test_2, test_1, START, END ), "jzzngu") ;
36
+  Test::assertEqual( Crypt::atbash( test_2, START, END ), "cbazyx") ;
37
+  
38
+  return 0;
39
+}

+ 29
- 0
src/Test.cpp View File

@@ -0,0 +1,29 @@
1
+#include "../include/Test.h"
2
+
3
+Test::Test( bool verbose = true ){
4
+  this->verbose = verbose;
5
+}
6
+
7
+bool Test::assertEqual( std::string result, std::string expected )
8
+{
9
+  if ( result == expected ){
10
+    std::cout << "[\033[32msuccess\033[0m] : result equals expectation : \033[36m" << result << "\033[0m" << std::endl;
11
+    return true;
12
+  }else{
13
+    std::cout << "[\033[31mfailure\033[0m] : result \033[36m: " << result << "\033[0m" << std::endl
14
+	      << "            expectation :\033[36m" << expected << std::endl;
15
+    return false;
16
+  }
17
+}
18
+
19
+bool Test::assertNotEqual( std::string result, std::string expected )
20
+{
21
+  if ( result == expected ){
22
+    std::cout << "[\033[31mfailure\033[0m] : result equals expectation : \033[36m" << result << "\033[0m" << std::endl;
23
+    return false;
24
+  }else{
25
+    std::cout << "[\033[32msuccess\033[0m] : result : \033[36m" << result << "\033[0m" << std::endl
26
+	      << "            expectation : \033[36m" << expected << "\033[0m" << std::endl;
27
+    return true;
28
+  }
29
+}

Loading…
Cancel
Save