Skip to content

Commit 333b4c1

Browse files
committed
add tests for problem 657. Judge Route Circle
1 parent 144e988 commit 333b4c1

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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+
}

judge_route_circle/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package judge_route_circle
2+
3+
func judgeCircle(moves string) bool {
4+
var result bool
5+
6+
return result
7+
8+
}

judge_route_circle/spec.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
657 Judge Route Circle
2+
https://leetcode.com/problems/judge-route-circle/description/
3+
4+
Initially, there is a Robot at position (0, 0). Given a sequence of its moves,
5+
judge if this robot makes a circle, which means it moves back to the original place.
6+
7+
The move sequence is represented by a string. And each move is represent by a character.
8+
The valid robot moves are R (Right), L (Left), U (Up) and D (down).
9+
The output should be true or false representing whether the robot makes a circle.
10+
11+
Example 1:
12+
```
13+
Input: "UD"
14+
Output: true
15+
```
16+
17+
Example 2:
18+
```
19+
Input: "LL"
20+
Output: false
21+
```

0 commit comments

Comments
 (0)