Skip to content

Commit e903963

Browse files
authored
luhn: Add generator and regenerate tests (#832)
* luhn: Add generator and regenerate tests * update function template [no important files changed]
1 parent b792d55 commit e903963

File tree

3 files changed

+60
-48
lines changed

3 files changed

+60
-48
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(ns luhn-test
2+
(:require [clojure.test :refer [deftest testing is]]
3+
luhn))
4+
5+
{{#test_cases.valid}}
6+
(deftest valid?_test_{{idx}}
7+
(testing {{context}}
8+
(is ({{#expected}}true?{{else}}false?{{/expected}} (luhn/valid? {{input.value}})))))
9+
{{/test_cases.valid}}
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
(ns luhn)
22

3-
(defn valid? [] ;; <- arglist goes here
4-
;; your code goes here
5-
)
3+
(defn valid?
4+
"Returns true if the given number is valid according
5+
to the luhn algorithm; otherwise, returns false."
6+
[s]
7+
;; function body
8+
)
Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,91 @@
11
(ns luhn-test
2-
(:require [clojure.test :refer [deftest is testing]]
2+
(:require [clojure.test :refer [deftest testing is]]
33
luhn))
44

5-
(deftest single-digit-strings-are-invalid
6-
(testing "Single digit strings can not be valid"
5+
(deftest valid?_test_1
6+
(testing "single digit strings can not be valid"
77
(is (false? (luhn/valid? "1")))))
88

9-
(deftest single-zero-is-invalid
10-
(testing "A single zero is invalid"
9+
(deftest valid?_test_2
10+
(testing "a single zero is invalid"
1111
(is (false? (luhn/valid? "0")))))
1212

13-
(deftest simple-valid-SIN-that-remains-valid-if-reversed
14-
(testing "A simple valid SIN that remains valid if reversed"
13+
(deftest valid?_test_3
14+
(testing "a simple valid SIN that remains valid if reversed"
1515
(is (true? (luhn/valid? "059")))))
1616

17-
(deftest simple-valid-SIN-that-becomes-invalid-if-reversed
18-
(testing "A simple valid SIN that becomes invalid if reversed"
17+
(deftest valid?_test_4
18+
(testing "a simple valid SIN that becomes invalid if reversed"
1919
(is (true? (luhn/valid? "59")))))
2020

21-
(deftest valid-canadian-SIN
22-
(testing "A valid Canadian SIN"
21+
(deftest valid?_test_5
22+
(testing "a valid Canadian SIN"
2323
(is (true? (luhn/valid? "055 444 285")))))
2424

25-
(deftest invalid-canadian-SIN
26-
(testing "Invalid Canadian SIN"
25+
(deftest valid?_test_6
26+
(testing "invalid Canadian SIN"
2727
(is (false? (luhn/valid? "055 444 286")))))
2828

29-
(deftest invalid-credit-card
30-
(testing "Invalid credit card"
29+
(deftest valid?_test_7
30+
(testing "invalid credit card"
3131
(is (false? (luhn/valid? "8273 1232 7352 0569")))))
3232

33-
(deftest invalid-long-number-with-an-even-remainder
34-
(testing "Invalid long number with an even remainder"
33+
(deftest valid?_test_8
34+
(testing "invalid long number with an even remainder"
3535
(is (false? (luhn/valid? "1 2345 6789 1234 5678 9012")))))
3636

37-
(deftest invalid-long-number-with-a-remainder-divisible-by-5
38-
(testing "Invalid long number with a remainder divisible by 5"
37+
(deftest valid?_test_9
38+
(testing "invalid long number with a remainder divisible by 5"
3939
(is (false? (luhn/valid? "1 2345 6789 1234 5678 9013")))))
4040

41-
(deftest valid-number-with-an-even-number-of-digits
42-
(testing "Valid number with an even number of digits"
41+
(deftest valid?_test_10
42+
(testing "valid number with an even number of digits"
4343
(is (true? (luhn/valid? "095 245 88")))))
4444

45-
(deftest valid-number-with-an-odd-number-of-spaces
46-
(testing "Valid number with an odd number of spaces"
45+
(deftest valid?_test_11
46+
(testing "valid number with an odd number of spaces"
4747
(is (true? (luhn/valid? "234 567 891 234")))))
4848

49-
(deftest valid-strings-with-a-non-digit-added-at-the-end-become-invalid
50-
(testing "Valid strings with a non-digit added at the end become invalid"
49+
(deftest valid?_test_12
50+
(testing "valid strings with a non-digit added at the end become invalid"
5151
(is (false? (luhn/valid? "059a")))))
5252

53-
(deftest valid-strings-with-punctuation-included-become-invalid
54-
(testing "Valid strings with punctuation included become invalid"
53+
(deftest valid?_test_13
54+
(testing "valid strings with punctuation included become invalid"
5555
(is (false? (luhn/valid? "055-444-285")))))
5656

57-
(deftest valid-strings-with-symbols-included-become-invalid
58-
(testing "Valid strings with symbols included become invalid"
57+
(deftest valid?_test_14
58+
(testing "valid strings with symbols included become invalid"
5959
(is (false? (luhn/valid? "055# 444$ 285")))))
6060

61-
(deftest single-zero-with-space-is-invalid
62-
(testing "Single zero with space is invalid"
61+
(deftest valid?_test_15
62+
(testing "single zero with space is invalid"
6363
(is (false? (luhn/valid? " 0")))))
6464

65-
(deftest more-than-a-single-zero-is-valid
66-
(testing "More than a single zero is valid"
65+
(deftest valid?_test_16
66+
(testing "more than a single zero is valid"
6767
(is (true? (luhn/valid? "0000 0")))))
6868

69-
(deftest input-digit-9-is-correctly-converted-to-output-digit-9
70-
(testing "Input digit 9 is correctly converted to output digit 9"
69+
(deftest valid?_test_17
70+
(testing "input digit 9 is correctly converted to output digit 9"
7171
(is (true? (luhn/valid? "091")))))
7272

73-
(deftest very-long-input-is-valid
74-
(testing "Very long input is valid"
73+
(deftest valid?_test_18
74+
(testing "very long input is valid"
7575
(is (true? (luhn/valid? "9999999999 9999999999 9999999999 9999999999")))))
7676

77-
(deftest valid-luhn-with-an-odd-number-of-digits-and-non-zero-first-digit
78-
(testing "Valid luhn with an odd number of digits and non zero first digit"
77+
(deftest valid?_test_19
78+
(testing "valid luhn with an odd number of digits and non zero first digit"
7979
(is (true? (luhn/valid? "109")))))
8080

81-
(deftest using-ascii-value-for-non-doubled-non-digit-is-not-allowed
82-
(testing "Using ascii value for non-doubled non-digit isn't allowed"
81+
(deftest valid?_test_20
82+
(testing "using ascii value for non-doubled non-digit isn't allowed"
8383
(is (false? (luhn/valid? "055b 444 285")))))
8484

85-
(deftest using-ascii-value-for-doubled-non-digit-is-not-allowed
86-
(testing "Using ascii value for doubled non-digit isn't allowed"
85+
(deftest valid?_test_21
86+
(testing "using ascii value for doubled non-digit isn't allowed"
8787
(is (false? (luhn/valid? ":9")))))
8888

89-
(deftest non-numeric-non-space-char-in-middle-with-sum-that-is-divisible-by-10-is-not-allowed
90-
(testing "Non-numeric, non-space char in the middle with a sum that's divisible by 10 isn't allowed"
89+
(deftest valid?_test_22
90+
(testing "non-numeric, non-space char in the middle with a sum that's divisible by 10 isn't allowed"
9191
(is (false? (luhn/valid? "59%59")))))

0 commit comments

Comments
 (0)