|
| 1 | +package judge_route_circle |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "testing" |
| 6 | +) |
| 7 | + |
| 8 | +type TestCase struct { |
| 9 | + id int |
| 10 | + description string |
| 11 | + input Input |
| 12 | + expectedResult ExpectedResult |
| 13 | +} |
| 14 | + |
| 15 | +type Input struct { |
| 16 | + moves string |
| 17 | +} |
| 18 | + |
| 19 | +type ExpectedResult struct { |
| 20 | + circle bool |
| 21 | +} |
| 22 | + |
| 23 | +type TestSuite []TestCase |
| 24 | + |
| 25 | +var ts = TestSuite{ |
| 26 | + TestCase{ |
| 27 | + id: 1, |
| 28 | + description: "test case from task - returned to start", |
| 29 | + input: Input{ |
| 30 | + moves: "UD", |
| 31 | + }, |
| 32 | + expectedResult: ExpectedResult{ |
| 33 | + circle: true, |
| 34 | + }, |
| 35 | + }, |
| 36 | + TestCase{ |
| 37 | + id: 2, |
| 38 | + description: "test case from task - not returned to start", |
| 39 | + input: Input{ |
| 40 | + moves: "LL", |
| 41 | + }, |
| 42 | + expectedResult: ExpectedResult{ |
| 43 | + circle: false, |
| 44 | + }, |
| 45 | + }, |
| 46 | + TestCase{ |
| 47 | + id: 3, |
| 48 | + description: "Not returned to start", |
| 49 | + input: Input{ |
| 50 | + moves: "ULUUDRLD", |
| 51 | + }, |
| 52 | + expectedResult: ExpectedResult{ |
| 53 | + circle: false, |
| 54 | + }, |
| 55 | + }, |
| 56 | + TestCase{ |
| 57 | + id: 4, |
| 58 | + description: "Not returned to start on y", |
| 59 | + input: Input{ |
| 60 | + moves: "ULUDUDRLD", |
| 61 | + }, |
| 62 | + expectedResult: ExpectedResult{ |
| 63 | + circle: false, |
| 64 | + }, |
| 65 | + }, |
| 66 | + TestCase{ |
| 67 | + id: 5, |
| 68 | + description: "Not returned to start on x", |
| 69 | + input: Input{ |
| 70 | + moves: "ULUUDRLDR", |
| 71 | + }, |
| 72 | + expectedResult: ExpectedResult{ |
| 73 | + circle: false, |
| 74 | + }, |
| 75 | + }, |
| 76 | + TestCase{ |
| 77 | + id: 6, |
| 78 | + description: "Returned to start after Long walk", |
| 79 | + input: Input{ |
| 80 | + moves: "ULUUDRLDRD", |
| 81 | + }, |
| 82 | + expectedResult: ExpectedResult{ |
| 83 | + circle: true, |
| 84 | + }, |
| 85 | + }, |
| 86 | +} |
| 87 | + |
| 88 | +func TestHamming(t *testing.T) { |
| 89 | + |
| 90 | + for _, tc := range ts { |
| 91 | + t.Run(fmt.Sprintf("Test%d", tc.id), func(t *testing.T) { |
| 92 | + |
| 93 | + actualResult := judgeCircle(tc.input.moves) |
| 94 | + |
| 95 | + if actualResult != tc.expectedResult.circle { |
| 96 | + fmt.Printf(" - Got: %v\n - Expected: %v\n", actualResult, tc.expectedResult.circle) |
| 97 | + t.Fail() |
| 98 | + } |
| 99 | + |
| 100 | + }) |
| 101 | + } |
| 102 | + |
| 103 | +} |
0 commit comments