Skip to content

Commit 0d8b691

Browse files
committed
TestFancy
1 parent c5502ee commit 0d8b691

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

fancy-sequence/Fancy_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package index
2+
3+
import (
4+
"testing"
5+
6+
"gotest.tools/v3/assert"
7+
)
8+
9+
func TestFancy(t *testing.T) {
10+
var fancy = Constructor()
11+
fancy.Append(2) // 奇妙序列:[2]
12+
fancy.AddAll(3) // 奇妙序列:[2+3] -> [5]
13+
fancy.Append(7) // 奇妙序列:[5, 7]
14+
fancy.MultAll(2) // 奇妙序列:[5*2, 7*2] -> [10, 14]
15+
assert.Equal(t, 10, fancy.GetIndex(0)) // 返回 10
16+
fancy.AddAll(3) // 奇妙序列:[10+3, 14+3] -> [13, 17]
17+
fancy.Append(10) // 奇妙序列:[13, 17, 10]
18+
fancy.MultAll(2) // 奇妙序列:[13*2, 17*2, 10*2] -> [26, 34, 20]
19+
assert.Equal(t, 26, fancy.GetIndex(0)) // 返回 26
20+
assert.Equal(t, 34, fancy.GetIndex(1)) // 返回 34
21+
assert.Equal(t, 20, fancy.GetIndex(2)) // 返回 20
22+
23+
}

go.work

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
go 1.19
22

33
use (
4+
./fancy-sequence
45
./abbreviating-the-product-of-a-range
56
.
67
./check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence
@@ -18,5 +19,5 @@ use (
1819
./transform-to-chessboard
1920
./utils
2021
./count-complete-tree-nodes
21-
./tree-of-coprimes
22+
./tree-of-coprimes
2223
)

remove-letter-to-equalize-frequency/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ import { countBy } from "../deps.ts";
33
function equalFrequency(word: string): boolean {
44
for (let i = 0; i < word.length; i++) {
55
const obj = countBy(word.slice(0, i) + word.slice(i + 1)),
6-
set = new Set();
7-
for (const k in obj) {
8-
set.add(obj[k]);
9-
}
6+
set = new Set<number>(Object.values(obj));
7+
108
if (set.size === 1) return true;
119
}
1210
return false;

0 commit comments

Comments
 (0)