|
| 1 | +/* |
| 2 | +Copyright 2023. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package controllers |
| 18 | + |
| 19 | +import "testing" |
| 20 | + |
| 21 | +func Test_giveGift(t *testing.T) { |
| 22 | + type args struct { |
| 23 | + amount int64 |
| 24 | + } |
| 25 | + tests := []struct { |
| 26 | + name string |
| 27 | + args args |
| 28 | + want int64 |
| 29 | + }{ |
| 30 | + // [1-298] -> 0%, [299-598] -> 10%, [599-1998] -> 15%, [1999-4998] -> 20%, [4999-19998] -> 25%, [19999+] -> 30% |
| 31 | + {name: "0% less than 299", args: args{amount: 100}, want: 0}, |
| 32 | + {name: "10% between 299 and 599", args: args{amount: 299}, want: 29}, |
| 33 | + {name: "10% between 299 and 599", args: args{amount: 300}, want: 30}, |
| 34 | + {name: "15% between 599 and 1999", args: args{amount: 599}, want: 89}, |
| 35 | + {name: "15% between 599 and 1999", args: args{amount: 600}, want: 90}, |
| 36 | + {name: "20% between 1999 and 4999", args: args{amount: 1999}, want: 399}, |
| 37 | + {name: "20% between 1999 and 4999", args: args{amount: 2000}, want: 400}, |
| 38 | + {name: "25% between 4999 and 19999", args: args{amount: 4999}, want: 1249}, |
| 39 | + {name: "25% between 4999 and 19999", args: args{amount: 5000}, want: 1250}, |
| 40 | + {name: "30% more than 19999", args: args{amount: 19999}, want: 5999}, |
| 41 | + {name: "30% more than 19999", args: args{amount: 20000}, want: 6000}, |
| 42 | + {name: "30% more than 19999", args: args{amount: 99999}, want: 29999}, |
| 43 | + } |
| 44 | + for _, tt := range tests { |
| 45 | + t.Run(tt.name, func(t *testing.T) { |
| 46 | + if got := giveGift(tt.args.amount); got != tt.want { |
| 47 | + t.Errorf("giveGift() = %v, want %v", got, tt.want) |
| 48 | + } |
| 49 | + }) |
| 50 | + } |
| 51 | +} |
0 commit comments