Skip to content

Commit ab12b5b

Browse files
author
Shuo
authored
Merge pull request #511 from openset/develop
Add: Valid Boomerang
2 parents 61ac2af + e8ea23a commit ab12b5b

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package valid_boomerang
2+
3+
func isBoomerang(points [][]int) bool {
4+
ans := points[0][0] * (points[1][1] - points[2][1])
5+
ans += points[1][0] * (points[2][1] - points[0][1])
6+
ans += points[2][0] * (points[0][1] - points[1][1])
7+
return ans != 0
8+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package valid_boomerang
2+
3+
import "testing"
4+
5+
type caseType struct {
6+
input [][]int
7+
expected bool
8+
}
9+
10+
func TestIsBoomerang(t *testing.T) {
11+
tests := [...]caseType{
12+
{
13+
input: [][]int{
14+
{1, 1},
15+
{2, 3},
16+
{3, 2},
17+
},
18+
expected: true,
19+
},
20+
{
21+
input: [][]int{
22+
{1, 1},
23+
{2, 2},
24+
{3, 3},
25+
},
26+
expected: false,
27+
},
28+
}
29+
for _, tc := range tests {
30+
output := isBoomerang(tc.input)
31+
if output != tc.expected {
32+
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)