@@ -6,104 +6,101 @@ public class ChangeTests
66 [ Fact ]
77 public void Change_for_1_cent ( )
88 {
9- var coins = new [ ] { 1 , 5 , 10 , 25 } ;
10- var target = 1 ;
11- var expected = new [ ] { 1 } ;
12- Assert . Equal ( expected , Change . FindFewestCoins ( coins , target ) ) ;
9+ int [ ] coins = [ 1 , 5 , 10 , 25 ] ;
10+ int [ ] expected = [ 1 ] ;
11+ Assert . Equal ( expected , Change . FindFewestCoins ( coins , 1 ) ) ;
1312 }
1413
1514 [ Fact ( Skip = "Remove this Skip property to run this test" ) ]
1615 public void Single_coin_change ( )
1716 {
18- var coins = new [ ] { 1 , 5 , 10 , 25 , 100 } ;
19- var target = 25 ;
20- var expected = new [ ] { 25 } ;
21- Assert . Equal ( expected , Change . FindFewestCoins ( coins , target ) ) ;
17+ int [ ] coins = [ 1 , 5 , 10 , 25 , 100 ] ;
18+ int [ ] expected = [ 25 ] ;
19+ Assert . Equal ( expected , Change . FindFewestCoins ( coins , 25 ) ) ;
2220 }
2321
2422 [ Fact ( Skip = "Remove this Skip property to run this test" ) ]
2523 public void Multiple_coin_change ( )
2624 {
27- var coins = new [ ] { 1 , 5 , 10 , 25 , 100 } ;
28- var target = 15 ;
29- var expected = new [ ] { 5 , 10 } ;
30- Assert . Equal ( expected , Change . FindFewestCoins ( coins , target ) ) ;
25+ int [ ] coins = [ 1 , 5 , 10 , 25 , 100 ] ;
26+ int [ ] expected = [ 5 , 10 ] ;
27+ Assert . Equal ( expected , Change . FindFewestCoins ( coins , 15 ) ) ;
3128 }
3229
3330 [ Fact ( Skip = "Remove this Skip property to run this test" ) ]
3431 public void Change_with_lilliputian_coins ( )
3532 {
36- var coins = new [ ] { 1 , 4 , 15 , 20 , 50 } ;
37- var target = 23 ;
38- var expected = new [ ] { 4 , 4 , 15 } ;
39- Assert . Equal ( expected , Change . FindFewestCoins ( coins , target ) ) ;
33+ int [ ] coins = [ 1 , 4 , 15 , 20 , 50 ] ;
34+ int [ ] expected = [ 4 , 4 , 15 ] ;
35+ Assert . Equal ( expected , Change . FindFewestCoins ( coins , 23 ) ) ;
4036 }
4137
4238 [ Fact ( Skip = "Remove this Skip property to run this test" ) ]
4339 public void Change_with_lower_elbonia_coins ( )
4440 {
45- var coins = new [ ] { 1 , 5 , 10 , 21 , 25 } ;
46- var target = 63 ;
47- var expected = new [ ] { 21 , 21 , 21 } ;
48- Assert . Equal ( expected , Change . FindFewestCoins ( coins , target ) ) ;
41+ int [ ] coins = [ 1 , 5 , 10 , 21 , 25 ] ;
42+ int [ ] expected = [ 21 , 21 , 21 ] ;
43+ Assert . Equal ( expected , Change . FindFewestCoins ( coins , 63 ) ) ;
4944 }
5045
5146 [ Fact ( Skip = "Remove this Skip property to run this test" ) ]
5247 public void Large_target_values ( )
5348 {
54- var coins = new [ ] { 1 , 2 , 5 , 10 , 20 , 50 , 100 } ;
55- var target = 999 ;
56- var expected = new [ ] { 2 , 2 , 5 , 20 , 20 , 50 , 100 , 100 , 100 , 100 , 100 , 100 , 100 , 100 , 100 } ;
57- Assert . Equal ( expected , Change . FindFewestCoins ( coins , target ) ) ;
49+ int [ ] coins = [ 1 , 2 , 5 , 10 , 20 , 50 , 100 ] ;
50+ int [ ] expected = [ 2 , 2 , 5 , 20 , 20 , 50 , 100 , 100 , 100 , 100 , 100 , 100 , 100 , 100 , 100 ] ;
51+ Assert . Equal ( expected , Change . FindFewestCoins ( coins , 999 ) ) ;
5852 }
5953
6054 [ Fact ( Skip = "Remove this Skip property to run this test" ) ]
6155 public void Possible_change_without_unit_coins_available ( )
6256 {
63- var coins = new [ ] { 2 , 5 , 10 , 20 , 50 } ;
64- var target = 21 ;
65- var expected = new [ ] { 2 , 2 , 2 , 5 , 10 } ;
66- Assert . Equal ( expected , Change . FindFewestCoins ( coins , target ) ) ;
57+ int [ ] coins = [ 2 , 5 , 10 , 20 , 50 ] ;
58+ int [ ] expected = [ 2 , 2 , 2 , 5 , 10 ] ;
59+ Assert . Equal ( expected , Change . FindFewestCoins ( coins , 21 ) ) ;
6760 }
6861
6962 [ Fact ( Skip = "Remove this Skip property to run this test" ) ]
7063 public void Another_possible_change_without_unit_coins_available ( )
7164 {
72- var coins = new [ ] { 4 , 5 } ;
73- var target = 27 ;
74- var expected = new [ ] { 4 , 4 , 4 , 5 , 5 , 5 } ;
75- Assert . Equal ( expected , Change . FindFewestCoins ( coins , target ) ) ;
65+ int [ ] coins = [ 4 , 5 ] ;
66+ int [ ] expected = [ 4 , 4 , 4 , 5 , 5 , 5 ] ;
67+ Assert . Equal ( expected , Change . FindFewestCoins ( coins , 27 ) ) ;
68+ }
69+
70+ [ Fact ( Skip = "Remove this Skip property to run this test" ) ]
71+ public void A_greedy_approach_is_not_optimal ( )
72+ {
73+ int [ ] coins = [ 1 , 10 , 11 ] ;
74+ int [ ] expected = [ 10 , 10 ] ;
75+ Assert . Equal ( expected , Change . FindFewestCoins ( coins , 20 ) ) ;
7676 }
7777
7878 [ Fact ( Skip = "Remove this Skip property to run this test" ) ]
7979 public void No_coins_make_0_change ( )
8080 {
81- var coins = new [ ] { 1 , 5 , 10 , 21 , 25 } ;
82- var target = 0 ;
83- Assert . Empty ( Change . FindFewestCoins ( coins , target ) ) ;
81+ int [ ] coins = [ 1 , 5 , 10 , 21 , 25 ] ;
82+ int [ ] expected = [ ] ;
83+ Assert . Equal ( expected , Change . FindFewestCoins ( coins , 0 ) ) ;
8484 }
8585
8686 [ Fact ( Skip = "Remove this Skip property to run this test" ) ]
8787 public void Error_testing_for_change_smaller_than_the_smallest_of_coins ( )
8888 {
89- var coins = new [ ] { 5 , 10 } ;
90- var target = 3 ;
91- Assert . Throws < ArgumentException > ( ( ) => Change . FindFewestCoins ( coins , target ) ) ;
89+ int [ ] coins = [ 5 , 10 ] ;
90+ Assert . Throws < ArgumentException > ( ( ) => Change . FindFewestCoins ( coins , 3 ) ) ;
9291 }
9392
9493 [ Fact ( Skip = "Remove this Skip property to run this test" ) ]
9594 public void Error_if_no_combination_can_add_up_to_target ( )
9695 {
97- var coins = new [ ] { 5 , 10 } ;
98- var target = 94 ;
99- Assert . Throws < ArgumentException > ( ( ) => Change . FindFewestCoins ( coins , target ) ) ;
96+ int [ ] coins = [ 5 , 10 ] ;
97+ Assert . Throws < ArgumentException > ( ( ) => Change . FindFewestCoins ( coins , 94 ) ) ;
10098 }
10199
102100 [ Fact ( Skip = "Remove this Skip property to run this test" ) ]
103101 public void Cannot_find_negative_change_values ( )
104102 {
105- var coins = new [ ] { 1 , 2 , 5 } ;
106- var target = - 5 ;
107- Assert . Throws < ArgumentException > ( ( ) => Change . FindFewestCoins ( coins , target ) ) ;
103+ int [ ] coins = [ 1 , 2 , 5 ] ;
104+ Assert . Throws < ArgumentException > ( ( ) => Change . FindFewestCoins ( coins , - 5 ) ) ;
108105 }
109106}
0 commit comments