3
3
[ TestFixture ]
4
4
public class LuhnTest
5
5
{
6
- [ Test ]
7
- public void Check_digit_is_the_rightmost_digit ( )
8
- {
9
- Assert . That ( new Luhn ( 34567 ) . CheckDigit , Is . EqualTo ( 7 ) ) ;
10
- }
11
-
12
- [ Ignore ( "Remove to run test" ) ]
13
- [ Test ]
14
- public void Addends_doubles_every_other_number_from_the_right ( )
15
- {
16
- Assert . That ( new Luhn ( 12121 ) . Addends , Is . EqualTo ( new [ ] { 1 , 4 , 1 , 4 , 1 } ) ) ;
17
- }
18
-
19
- [ Ignore ( "Remove to run test" ) ]
20
- [ Test ]
21
- public void Addends_subtracts_9_when_doubled_number_is_more_than_9 ( )
22
- {
23
- Assert . That ( new Luhn ( 8631 ) . Addends , Is . EqualTo ( new [ ] { 7 , 6 , 6 , 1 } ) ) ;
24
- }
25
-
26
- [ Ignore ( "Remove to run test" ) ]
27
- [ TestCase ( 4913 , ExpectedResult = 22 ) ]
28
- [ TestCase ( 201773 , ExpectedResult = 21 ) ]
29
- public int Checksum_adds_addends_together ( int number )
30
- {
31
- return new Luhn ( number ) . Checksum ;
32
- }
33
-
34
- [ Ignore ( "Remove to run test" ) ]
35
- [ TestCase ( 738 , ExpectedResult = false ) ]
36
- [ TestCase ( 8739567 , ExpectedResult = true ) ]
37
- public bool Number_is_valid_when_checksum_mod_10_is_zero ( int number )
38
- {
39
- return new Luhn ( number ) . Valid ;
40
- }
41
-
42
- [ Ignore ( "Remove to run test" ) ]
43
- [ Test ]
44
- public void Luhn_can_create_simple_numbers_with_valid_check_digit ( )
45
- {
46
- Assert . That ( Luhn . Create ( 123 ) , Is . EqualTo ( 1230 ) ) ;
47
- }
48
-
49
- [ Ignore ( "Remove to run test" ) ]
50
- [ Test ]
51
- public void Luhn_can_create_larger_numbers_with_valid_check_digit ( )
52
- {
53
- Assert . That ( Luhn . Create ( 873956 ) , Is . EqualTo ( 8739567 ) ) ;
54
- }
55
-
56
- [ Ignore ( "Remove to run test" ) ]
57
- [ Test ]
58
- public void Luhn_can_create_huge_numbers_with_valid_check_digit ( )
59
- {
60
- Assert . That ( Luhn . Create ( 837263756 ) , Is . EqualTo ( 8372637564 ) ) ;
6
+ [ TestCase ( "1" , ExpectedResult = false ) ] // single digit strings can not be valid
7
+ [ TestCase ( "0" , ExpectedResult = false , Ignore = "Remove to run test" ) ] // a single zero is invalid
8
+ [ TestCase ( "046 454 286" , ExpectedResult = true , Ignore = "Remove to run test" ) ] // valid Canadian SIN
9
+ [ TestCase ( "046 454 287" , ExpectedResult = false , Ignore = "Remove to run test" ) ] // invalid Canadian SIN
10
+ [ TestCase ( "8273 1232 7352 0569" , ExpectedResult = false , Ignore = "Remove to run test" ) ] // invalid credit card
11
+ [ TestCase ( "827a 1232 7352 0569" , ExpectedResult = false , Ignore = "Remove to run test" ) ] // strings that contain non-digits are not valid
12
+ public bool ValidateChecksum ( string number )
13
+ {
14
+ return Luhn . IsValid ( number ) ;
61
15
}
62
16
}
0 commit comments