瀏覽代碼

Merge pull request #191 from MikeMirzayanov/skip-bounds-checks

Skip bounds check(s) with var name syntax
Mike Mirzayanov 7 月之前
父節點
當前提交
cdd4ffda2b
共有 91 個文件被更改,包括 341 次插入13 次删除
  1. 43 12
      testlib.h
  2. 3 1
      tests/scripts/test-ref
  3. 3 0
      tests/test-007_validators/files/unix/input.01
  4. 7 0
      tests/test-007_validators/files/unix/input.02
  5. 7 0
      tests/test-007_validators/files/unix/input.03
  6. 5 0
      tests/test-007_validators/files/unix/input.04
  7. 9 0
      tests/test-007_validators/files/unix/input.05
  8. 5 0
      tests/test-007_validators/files/unix/input.06
  9. 3 0
      tests/test-007_validators/files/win/input.01
  10. 7 0
      tests/test-007_validators/files/win/input.02
  11. 7 0
      tests/test-007_validators/files/win/input.03
  12. 5 0
      tests/test-007_validators/files/win/input.04
  13. 9 0
      tests/test-007_validators/files/win/input.05
  14. 5 0
      tests/test-007_validators/files/win/input.06
  15. 1 0
      tests/test-007_validators/refs/v1-01/exit_code
  16. 3 0
      tests/test-007_validators/refs/v1-01/stderr
  17. 0 0
      tests/test-007_validators/refs/v1-01/stdout
  18. 1 0
      tests/test-007_validators/refs/v1-02/exit_code
  19. 3 0
      tests/test-007_validators/refs/v1-02/stderr
  20. 0 0
      tests/test-007_validators/refs/v1-02/stdout
  21. 1 0
      tests/test-007_validators/refs/v1-03/exit_code
  22. 1 0
      tests/test-007_validators/refs/v1-03/stderr
  23. 0 0
      tests/test-007_validators/refs/v1-03/stdout
  24. 1 0
      tests/test-007_validators/refs/v1-04/exit_code
  25. 3 0
      tests/test-007_validators/refs/v1-04/stderr
  26. 0 0
      tests/test-007_validators/refs/v1-04/stdout
  27. 1 0
      tests/test-007_validators/refs/v1-05/exit_code
  28. 1 0
      tests/test-007_validators/refs/v1-05/stderr
  29. 0 0
      tests/test-007_validators/refs/v1-05/stdout
  30. 1 0
      tests/test-007_validators/refs/v1-06/exit_code
  31. 3 0
      tests/test-007_validators/refs/v1-06/stderr
  32. 0 0
      tests/test-007_validators/refs/v1-06/stdout
  33. 1 0
      tests/test-007_validators/refs/v2-01/exit_code
  34. 3 0
      tests/test-007_validators/refs/v2-01/stderr
  35. 0 0
      tests/test-007_validators/refs/v2-01/stdout
  36. 1 0
      tests/test-007_validators/refs/v2-02/exit_code
  37. 3 0
      tests/test-007_validators/refs/v2-02/stderr
  38. 0 0
      tests/test-007_validators/refs/v2-02/stdout
  39. 1 0
      tests/test-007_validators/refs/v2-03/exit_code
  40. 1 0
      tests/test-007_validators/refs/v2-03/stderr
  41. 0 0
      tests/test-007_validators/refs/v2-03/stdout
  42. 1 0
      tests/test-007_validators/refs/v2-04/exit_code
  43. 3 0
      tests/test-007_validators/refs/v2-04/stderr
  44. 0 0
      tests/test-007_validators/refs/v2-04/stdout
  45. 1 0
      tests/test-007_validators/refs/v2-05/exit_code
  46. 1 0
      tests/test-007_validators/refs/v2-05/stderr
  47. 0 0
      tests/test-007_validators/refs/v2-05/stdout
  48. 1 0
      tests/test-007_validators/refs/v2-06/exit_code
  49. 3 0
      tests/test-007_validators/refs/v2-06/stderr
  50. 0 0
      tests/test-007_validators/refs/v2-06/stdout
  51. 1 0
      tests/test-007_validators/refs/v3-01/exit_code
  52. 5 0
      tests/test-007_validators/refs/v3-01/stderr
  53. 0 0
      tests/test-007_validators/refs/v3-01/stdout
  54. 1 0
      tests/test-007_validators/refs/v3-02/exit_code
  55. 5 0
      tests/test-007_validators/refs/v3-02/stderr
  56. 0 0
      tests/test-007_validators/refs/v3-02/stdout
  57. 1 0
      tests/test-007_validators/refs/v3-03/exit_code
  58. 1 0
      tests/test-007_validators/refs/v3-03/stderr
  59. 0 0
      tests/test-007_validators/refs/v3-03/stdout
  60. 1 0
      tests/test-007_validators/refs/v3-04/exit_code
  61. 5 0
      tests/test-007_validators/refs/v3-04/stderr
  62. 0 0
      tests/test-007_validators/refs/v3-04/stdout
  63. 1 0
      tests/test-007_validators/refs/v3-05/exit_code
  64. 1 0
      tests/test-007_validators/refs/v3-05/stderr
  65. 0 0
      tests/test-007_validators/refs/v3-05/stdout
  66. 1 0
      tests/test-007_validators/refs/v3-06/exit_code
  67. 5 0
      tests/test-007_validators/refs/v3-06/stderr
  68. 0 0
      tests/test-007_validators/refs/v3-06/stdout
  69. 1 0
      tests/test-007_validators/refs/v4-01/exit_code
  70. 5 0
      tests/test-007_validators/refs/v4-01/stderr
  71. 0 0
      tests/test-007_validators/refs/v4-01/stdout
  72. 1 0
      tests/test-007_validators/refs/v4-02/exit_code
  73. 5 0
      tests/test-007_validators/refs/v4-02/stderr
  74. 0 0
      tests/test-007_validators/refs/v4-02/stdout
  75. 1 0
      tests/test-007_validators/refs/v4-03/exit_code
  76. 1 0
      tests/test-007_validators/refs/v4-03/stderr
  77. 0 0
      tests/test-007_validators/refs/v4-03/stdout
  78. 1 0
      tests/test-007_validators/refs/v4-04/exit_code
  79. 5 0
      tests/test-007_validators/refs/v4-04/stderr
  80. 0 0
      tests/test-007_validators/refs/v4-04/stdout
  81. 1 0
      tests/test-007_validators/refs/v4-05/exit_code
  82. 1 0
      tests/test-007_validators/refs/v4-05/stderr
  83. 0 0
      tests/test-007_validators/refs/v4-05/stdout
  84. 1 0
      tests/test-007_validators/refs/v4-06/exit_code
  85. 5 0
      tests/test-007_validators/refs/v4-06/stderr
  86. 0 0
      tests/test-007_validators/refs/v4-06/stdout
  87. 19 0
      tests/test-007_validators/run.sh
  88. 27 0
      tests/test-007_validators/src/v1.cpp
  89. 27 0
      tests/test-007_validators/src/v2.cpp
  90. 27 0
      tests/test-007_validators/src/v3.cpp
  91. 27 0
      tests/test-007_validators/src/v4.cpp

+ 43 - 12
testlib.h

@@ -2352,10 +2352,10 @@ struct ValidatorBoundsHit {
     ValidatorBoundsHit(bool minHit = false, bool maxHit = false) : minHit(minHit), maxHit(maxHit) {
     };
 
-    ValidatorBoundsHit merge(const ValidatorBoundsHit &validatorBoundsHit) {
+    ValidatorBoundsHit merge(const ValidatorBoundsHit &validatorBoundsHit, bool ignoreMinBound, bool ignoreMaxBound) {
         return ValidatorBoundsHit(
-                __testlib_max(minHit, validatorBoundsHit.minHit),
-                __testlib_max(maxHit, validatorBoundsHit.maxHit)
+                __testlib_max(minHit, validatorBoundsHit.minHit) || ignoreMinBound,
+                __testlib_max(maxHit, validatorBoundsHit.maxHit) || ignoreMaxBound
         );
     }
 };
@@ -2455,10 +2455,31 @@ public:
         _testCaseFileName = testCaseFileName;
     }
 
+    std::string prepVariableName(const std::string &variableName) {
+        if (variableName.length() >= 2 && variableName != "~~") {
+            if (variableName[0] == '~' && variableName.back() != '~')
+                return variableName.substr(1);
+            if (variableName[0] != '~' && variableName.back() == '~')
+                return variableName.substr(0, variableName.length() - 1);
+            if (variableName[0] == '~' && variableName.back() == '~')
+                return variableName.substr(1, variableName.length() - 2);
+        }
+        return variableName;
+    }
+
+    bool ignoreMinBound(const std::string &variableName) {
+        return variableName.length() >= 2 && variableName != "~~" && variableName[0] == '~';
+    }
+
+    bool ignoreMaxBound(const std::string &variableName) {
+        return variableName.length() >= 2 && variableName != "~~" && variableName.back() == '~';
+    }
+
     void addBoundsHit(const std::string &variableName, ValidatorBoundsHit boundsHit) {
         if (isVariableNameBoundsAnalyzable(variableName)) {
-            _boundsHitByVariableName[variableName]
-                    = boundsHit.merge(_boundsHitByVariableName[variableName]);
+            std::string preparedVariableName = prepVariableName(variableName);
+            _boundsHitByVariableName[preparedVariableName] = boundsHit.merge(_boundsHitByVariableName[preparedVariableName],
+                ignoreMinBound(variableName), ignoreMaxBound(variableName));
         }
     }
 
@@ -2494,13 +2515,23 @@ public:
         if (!_testOverviewLogFileName.empty()) {
             std::string fileName(_testOverviewLogFileName);
             _testOverviewLogFileName = "";
-            FILE *testOverviewLogFile = fopen(fileName.c_str(), "w");
-            if (NULL == testOverviewLogFile)
-                __testlib_fail("Validator::writeTestOverviewLog: can't write test overview log to (" + fileName + ")");
-            fprintf(testOverviewLogFile, "%s%s", getBoundsHitLog().c_str(), getFeaturesLog().c_str());
-            if (fclose(testOverviewLogFile))
-                __testlib_fail(
-                        "Validator::writeTestOverviewLog: can't close test overview log file (" + fileName + ")");
+
+            FILE* f;
+            bool standard_file = false;
+            if (fileName == "stdout")
+                f = stdout, standard_file = true;
+            else if (fileName == "stderr")
+                f = stderr, standard_file = true;
+            else {
+                f = fopen(fileName.c_str(), "wb");
+                if (NULL == f)
+                    __testlib_fail("Validator::writeTestOverviewLog: can't write test overview log to (" + fileName + ")");
+            }
+            fprintf(f, "%s%s", getBoundsHitLog().c_str(), getFeaturesLog().c_str());
+            std::fflush(f);
+            if (!standard_file)
+                if (std::fclose(f))
+                    __testlib_fail("Validator::writeTestOverviewLog: can't close test overview log file (" + fileName + ")");
         }
     }
 

+ 3 - 1
tests/scripts/test-ref

@@ -72,7 +72,9 @@ else
   exit_code=0
   # shellcheck disable=SC2048
   $* 1>"$refs"/stdout.aux 2>"$refs"/stderr.aux || exit_code=$?
-  echo "Program exit code: $exit_code, stdout size: $(stat -c %s "$refs"/stdout.aux) bytes, stderr size: $(stat -c %s "$refs"/stderr.aux) bytes"
+  stdout_size=$(wc -c < "$refs"/stdout.aux)
+  stderr_size=$(wc -c < "$refs"/stderr.aux)
+  echo "Program exit code: $exit_code, stdout size: $stdout_size bytes, stderr size: $stderr_size bytes"
   echo $exit_code >"$refs"/exit_code.aux
 
   # Check exit code is the same

+ 3 - 0
tests/test-007_validators/files/unix/input.01

@@ -0,0 +1,3 @@
+1
+2 0 0
+1 2

+ 7 - 0
tests/test-007_validators/files/unix/input.02

@@ -0,0 +1,7 @@
+3
+1 0 0
+1
+2 0 0
+2 1
+4 0 0
+1 2 3 4

+ 7 - 0
tests/test-007_validators/files/unix/input.03

@@ -0,0 +1,7 @@
+3
+1 0 0
+1
+2 0 0
+2 1
+4 0 0
+1 2 2 4

+ 5 - 0
tests/test-007_validators/files/unix/input.04

@@ -0,0 +1,5 @@
+2
+2 0 0
+1 2
+3 0 0
+1 3 2

+ 9 - 0
tests/test-007_validators/files/unix/input.05

@@ -0,0 +1,9 @@
+4
+2 0 0
+1 2
+3 0 0
+1 3 2
+2 0 0
+1 2
+3 0 0
+1 3 2

+ 5 - 0
tests/test-007_validators/files/unix/input.06

@@ -0,0 +1,5 @@
+2
+4 -2 -5
+1 2 3 4
+4 2 5
+1 2 3 4

+ 3 - 0
tests/test-007_validators/files/win/input.01

@@ -0,0 +1,3 @@
+1
+2 0 0
+1 2

+ 7 - 0
tests/test-007_validators/files/win/input.02

@@ -0,0 +1,7 @@
+3
+1 0 0
+1
+2 0 0
+2 1
+4 0 0
+1 2 3 4

+ 7 - 0
tests/test-007_validators/files/win/input.03

@@ -0,0 +1,7 @@
+3
+1 0 0
+1
+2 0 0
+2 1
+4 0 0
+1 2 2 4

+ 5 - 0
tests/test-007_validators/files/win/input.04

@@ -0,0 +1,5 @@
+2
+2 0 0
+1 2
+3 0 0
+1 3 2

+ 9 - 0
tests/test-007_validators/files/win/input.05

@@ -0,0 +1,9 @@
+4
+2 0 0
+1 2
+3 0 0
+1 3 2
+2 0 0
+1 2
+3 0 0
+1 3 2

+ 5 - 0
tests/test-007_validators/files/win/input.06

@@ -0,0 +1,5 @@
+2
+4 -2 -5
+1 2 3 4
+4 2 5
+1 2 3 4

+ 1 - 0
tests/test-007_validators/refs/v1-01/exit_code

@@ -0,0 +1 @@
+0

+ 3 - 0
tests/test-007_validators/refs/v1-01/stderr

@@ -0,0 +1,3 @@
+"a": min-value-hit max-value-hit
+"n":
+"t": min-value-hit

+ 0 - 0
tests/test-007_validators/refs/v1-01/stdout


+ 1 - 0
tests/test-007_validators/refs/v1-02/exit_code

@@ -0,0 +1 @@
+0

+ 3 - 0
tests/test-007_validators/refs/v1-02/stderr

@@ -0,0 +1,3 @@
+"a": min-value-hit max-value-hit
+"n": min-value-hit max-value-hit
+"t": max-value-hit

+ 0 - 0
tests/test-007_validators/refs/v1-02/stdout


+ 1 - 0
tests/test-007_validators/refs/v1-03/exit_code

@@ -0,0 +1 @@
+3

+ 1 - 0
tests/test-007_validators/refs/v1-03/stderr

@@ -0,0 +1 @@
+FAIL not a permutation (duplicates) (test case 4)

+ 0 - 0
tests/test-007_validators/refs/v1-03/stdout


+ 1 - 0
tests/test-007_validators/refs/v1-04/exit_code

@@ -0,0 +1 @@
+0

+ 3 - 0
tests/test-007_validators/refs/v1-04/stderr

@@ -0,0 +1,3 @@
+"a": min-value-hit max-value-hit
+"n":
+"t":

+ 0 - 0
tests/test-007_validators/refs/v1-04/stdout


+ 1 - 0
tests/test-007_validators/refs/v1-05/exit_code

@@ -0,0 +1 @@
+3

+ 1 - 0
tests/test-007_validators/refs/v1-05/stderr

@@ -0,0 +1 @@
+FAIL Integer parameter [name=t] equals to 4, violates the range [1, 3] (stdin, line 1)

+ 0 - 0
tests/test-007_validators/refs/v1-05/stdout


+ 1 - 0
tests/test-007_validators/refs/v1-06/exit_code

@@ -0,0 +1 @@
+0

+ 3 - 0
tests/test-007_validators/refs/v1-06/stderr

@@ -0,0 +1,3 @@
+"a": min-value-hit max-value-hit
+"n": max-value-hit
+"t":

+ 0 - 0
tests/test-007_validators/refs/v1-06/stdout


+ 1 - 0
tests/test-007_validators/refs/v2-01/exit_code

@@ -0,0 +1 @@
+0

+ 3 - 0
tests/test-007_validators/refs/v2-01/stderr

@@ -0,0 +1,3 @@
+"a": min-value-hit max-value-hit
+"n": max-value-hit
+"t": min-value-hit

+ 0 - 0
tests/test-007_validators/refs/v2-01/stdout


+ 1 - 0
tests/test-007_validators/refs/v2-02/exit_code

@@ -0,0 +1 @@
+0

+ 3 - 0
tests/test-007_validators/refs/v2-02/stderr

@@ -0,0 +1,3 @@
+"a": min-value-hit max-value-hit
+"n": min-value-hit max-value-hit
+"t": min-value-hit max-value-hit

+ 0 - 0
tests/test-007_validators/refs/v2-02/stdout


+ 1 - 0
tests/test-007_validators/refs/v2-03/exit_code

@@ -0,0 +1 @@
+3

+ 1 - 0
tests/test-007_validators/refs/v2-03/stderr

@@ -0,0 +1 @@
+FAIL not a permutation (duplicates) (test case 4)

+ 0 - 0
tests/test-007_validators/refs/v2-03/stdout


+ 1 - 0
tests/test-007_validators/refs/v2-04/exit_code

@@ -0,0 +1 @@
+0

+ 3 - 0
tests/test-007_validators/refs/v2-04/stderr

@@ -0,0 +1,3 @@
+"a": min-value-hit max-value-hit
+"n": max-value-hit
+"t": min-value-hit

+ 0 - 0
tests/test-007_validators/refs/v2-04/stdout


+ 1 - 0
tests/test-007_validators/refs/v2-05/exit_code

@@ -0,0 +1 @@
+3

+ 1 - 0
tests/test-007_validators/refs/v2-05/stderr

@@ -0,0 +1 @@
+FAIL Integer parameter [name=~t] equals to 4, violates the range [1, 3] (stdin, line 1)

+ 0 - 0
tests/test-007_validators/refs/v2-05/stdout


+ 1 - 0
tests/test-007_validators/refs/v2-06/exit_code

@@ -0,0 +1 @@
+0

+ 3 - 0
tests/test-007_validators/refs/v2-06/stderr

@@ -0,0 +1,3 @@
+"a": min-value-hit max-value-hit
+"n": max-value-hit
+"t": min-value-hit

+ 0 - 0
tests/test-007_validators/refs/v2-06/stdout


+ 1 - 0
tests/test-007_validators/refs/v3-01/exit_code

@@ -0,0 +1 @@
+0

+ 5 - 0
tests/test-007_validators/refs/v3-01/stderr

@@ -0,0 +1,5 @@
+"a": min-value-hit max-value-hit
+"l":
+"n": min-value-hit
+"r":
+"t": min-value-hit max-value-hit

+ 0 - 0
tests/test-007_validators/refs/v3-01/stdout


+ 1 - 0
tests/test-007_validators/refs/v3-02/exit_code

@@ -0,0 +1 @@
+0

+ 5 - 0
tests/test-007_validators/refs/v3-02/stderr

@@ -0,0 +1,5 @@
+"a": min-value-hit max-value-hit
+"l":
+"n": min-value-hit max-value-hit
+"r":
+"t": min-value-hit max-value-hit

+ 0 - 0
tests/test-007_validators/refs/v3-02/stdout


+ 1 - 0
tests/test-007_validators/refs/v3-03/exit_code

@@ -0,0 +1 @@
+3

+ 1 - 0
tests/test-007_validators/refs/v3-03/stderr

@@ -0,0 +1 @@
+FAIL not a permutation (duplicates) (test case 4)

+ 0 - 0
tests/test-007_validators/refs/v3-03/stdout


+ 1 - 0
tests/test-007_validators/refs/v3-04/exit_code

@@ -0,0 +1 @@
+0

+ 5 - 0
tests/test-007_validators/refs/v3-04/stderr

@@ -0,0 +1,5 @@
+"a": min-value-hit max-value-hit
+"l":
+"n": min-value-hit
+"r":
+"t": min-value-hit max-value-hit

+ 0 - 0
tests/test-007_validators/refs/v3-04/stdout


+ 1 - 0
tests/test-007_validators/refs/v3-05/exit_code

@@ -0,0 +1 @@
+3

+ 1 - 0
tests/test-007_validators/refs/v3-05/stderr

@@ -0,0 +1 @@
+FAIL Integer parameter [name=~t~] equals to 4, violates the range [1, 3] (stdin, line 1)

+ 0 - 0
tests/test-007_validators/refs/v3-05/stdout


+ 1 - 0
tests/test-007_validators/refs/v3-06/exit_code

@@ -0,0 +1 @@
+0

+ 5 - 0
tests/test-007_validators/refs/v3-06/stderr

@@ -0,0 +1,5 @@
+"a": min-value-hit max-value-hit
+"l": min-value-hit max-value-hit
+"n": min-value-hit max-value-hit
+"r": min-value-hit max-value-hit
+"t": min-value-hit max-value-hit

+ 0 - 0
tests/test-007_validators/refs/v3-06/stdout


+ 1 - 0
tests/test-007_validators/refs/v4-01/exit_code

@@ -0,0 +1 @@
+0

+ 5 - 0
tests/test-007_validators/refs/v4-01/stderr

@@ -0,0 +1,5 @@
+"a": min-value-hit max-value-hit
+"l": max-value-hit
+"n": min-value-hit
+"r": min-value-hit max-value-hit
+"t": min-value-hit max-value-hit

+ 0 - 0
tests/test-007_validators/refs/v4-01/stdout


+ 1 - 0
tests/test-007_validators/refs/v4-02/exit_code

@@ -0,0 +1 @@
+0

+ 5 - 0
tests/test-007_validators/refs/v4-02/stderr

@@ -0,0 +1,5 @@
+"a": min-value-hit max-value-hit
+"l": max-value-hit
+"n": min-value-hit max-value-hit
+"r": min-value-hit max-value-hit
+"t": min-value-hit max-value-hit

+ 0 - 0
tests/test-007_validators/refs/v4-02/stdout


+ 1 - 0
tests/test-007_validators/refs/v4-03/exit_code

@@ -0,0 +1 @@
+3

+ 1 - 0
tests/test-007_validators/refs/v4-03/stderr

@@ -0,0 +1 @@
+FAIL not a permutation (duplicates) (test case 4)

+ 0 - 0
tests/test-007_validators/refs/v4-03/stdout


+ 1 - 0
tests/test-007_validators/refs/v4-04/exit_code

@@ -0,0 +1 @@
+0

+ 5 - 0
tests/test-007_validators/refs/v4-04/stderr

@@ -0,0 +1,5 @@
+"a": min-value-hit max-value-hit
+"l": max-value-hit
+"n": min-value-hit
+"r": min-value-hit max-value-hit
+"t": min-value-hit max-value-hit

+ 0 - 0
tests/test-007_validators/refs/v4-04/stdout


+ 1 - 0
tests/test-007_validators/refs/v4-05/exit_code

@@ -0,0 +1 @@
+3

+ 1 - 0
tests/test-007_validators/refs/v4-05/stderr

@@ -0,0 +1 @@
+FAIL Integer parameter [name=~t~] equals to 4, violates the range [1, 3] (stdin, line 1)

+ 0 - 0
tests/test-007_validators/refs/v4-05/stdout


+ 1 - 0
tests/test-007_validators/refs/v4-06/exit_code

@@ -0,0 +1 @@
+0

+ 5 - 0
tests/test-007_validators/refs/v4-06/stderr

@@ -0,0 +1,5 @@
+"a": min-value-hit max-value-hit
+"l": min-value-hit max-value-hit
+"n": min-value-hit max-value-hit
+"r": min-value-hit max-value-hit
+"t": min-value-hit max-value-hit

+ 0 - 0
tests/test-007_validators/refs/v4-06/stdout


+ 19 - 0
tests/test-007_validators/run.sh

@@ -0,0 +1,19 @@
+#!/bin/bash
+set -eo pipefail
+
+os="unix"
+if [[ "$MACHINE" == "Windows" ]]; then
+  os="win"
+fi
+
+# Loop through the versions v1, v2, v3, and v4
+for version in v1 v2 v3 v4; do
+    bash ../scripts/compile src/"$version".cpp
+    
+    # Loop through the test numbers 01, 02, 03, and 04
+    for test_num in 01 02 03 04 05 06; do
+        bash ../scripts/test-ref "$version"-"$test_num" "$VALGRIND" ./"$version" --testOverviewLogFileName stderr < files/"$os"/input."$test_num"
+    done
+    
+    rm -f "$version" "$version".exe
+done

+ 27 - 0
tests/test-007_validators/src/v1.cpp

@@ -0,0 +1,27 @@
+#include "testlib.h"
+
+using namespace std;
+
+int main(int argc, char *argv[]) {
+    registerValidation(argc, argv);
+
+    int t = inf.readInt(1, 3, "t");
+    inf.readEoln();
+
+    for (int tt = 1; tt <= t; tt++) {
+        setTestCase(tt + 1);
+        
+        int n = inf.readInt(1, 4, "n");
+        inf.readSpace();
+        inf.readInt(-2, 2, "l0");
+        inf.readSpace();
+        inf.readInt(-5, 5, "r[1]");
+        inf.readEoln();
+
+        vector<int> a = inf.readInts(n, 1, n, "a");
+        ensuref(int(set<int>(a.begin(), a.end()).size()) == n, "not a permutation (duplicates)");
+        inf.readEoln();
+    }
+
+    inf.readEof();
+}

+ 27 - 0
tests/test-007_validators/src/v2.cpp

@@ -0,0 +1,27 @@
+#include "testlib.h"
+
+using namespace std;
+
+int main(int argc, char *argv[]) {
+    registerValidation(argc, argv);
+
+    int t = inf.readInt(1, 3, "~t");
+    inf.readEoln();
+
+    for (int tt = 1; tt <= t; tt++) {
+        setTestCase(tt + 1);
+        
+        int n = inf.readInt(1, 4, "n~");
+        inf.readSpace();
+        inf.readInt(-2, 2, "l0l");
+        inf.readSpace();
+        inf.readInt(-5, 5, "r1d");
+        inf.readEoln();
+
+        vector<int> a = inf.readInts(n, 1, n, "a");
+        ensuref(int(set<int>(a.begin(), a.end()).size()) == n, "not a permutation (duplicates)");
+        inf.readEoln();
+    }
+
+    inf.readEof();
+}

+ 27 - 0
tests/test-007_validators/src/v3.cpp

@@ -0,0 +1,27 @@
+#include "testlib.h"
+
+using namespace std;
+
+int main(int argc, char *argv[]) {
+    registerValidation(argc, argv);
+
+    int t = inf.readInt(1, 3, "~t~");
+    inf.readEoln();
+
+    for (int tt = 1; tt <= t; tt++) {
+        setTestCase(tt + 1);
+        
+        int n = inf.readInt(1, 4, "~n");
+        inf.readSpace();
+        inf.readInt(-2, 2, "l");
+        inf.readSpace();
+        inf.readInt(-5, 5, "r");
+        inf.readEoln();
+
+        vector<int> a = inf.readInts(n, 1, n, "~a");
+        ensuref(int(set<int>(a.begin(), a.end()).size()) == n, "not a permutation (duplicates)");
+        inf.readEoln();
+    }
+
+    inf.readEof();
+}

+ 27 - 0
tests/test-007_validators/src/v4.cpp

@@ -0,0 +1,27 @@
+#include "testlib.h"
+
+using namespace std;
+
+int main(int argc, char *argv[]) {
+    registerValidation(argc, argv);
+
+    int t = inf.readInt(1, 3, "~t~");
+    inf.readEoln();
+
+    for (int tt = 1; tt <= t; tt++) {
+        setTestCase(tt + 1);
+        
+        int n = inf.readInt(1, 4, "~n");
+        inf.readSpace();
+        inf.readInt(-2, 2, "l~");
+        inf.readSpace();
+        inf.readInt(-5, 5, "~r~");
+        inf.readEoln();
+
+        vector<int> a = inf.readInts(n, 1, n, "~a~");
+        ensuref(int(set<int>(a.begin(), a.end()).size()) == n, "not a permutation (duplicates)");
+        inf.readEoln();
+    }
+
+    inf.readEof();
+}