aboutsummaryrefslogtreecommitdiff
path: root/lib/strings/statistic_example_test.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-08-03 22:27:33 +0700
committerShulhan <ms@kilabit.info>2022-08-03 22:27:33 +0700
commitec98ea095fa85b5a4b64bd7ad37414c30d14310e (patch)
treea0d0af0ad27852b1644972ee2b11e870ea5acc03 /lib/strings/statistic_example_test.go
parent39d9c20c35a11c44cdd27783e407c1225027d820 (diff)
downloadpakakeh.go-ec98ea095fa85b5a4b64bd7ad37414c30d14310e.tar.xz
lib/strings: clean up test codes
Changes, * Use test.Data for test that require longer text input and output * Replace variable declaration ":=" with explicit one. * Use literal string
Diffstat (limited to 'lib/strings/statistic_example_test.go')
-rw-r--r--lib/strings/statistic_example_test.go66
1 files changed, 42 insertions, 24 deletions
diff --git a/lib/strings/statistic_example_test.go b/lib/strings/statistic_example_test.go
index e3df7d56..be989d64 100644
--- a/lib/strings/statistic_example_test.go
+++ b/lib/strings/statistic_example_test.go
@@ -9,89 +9,107 @@ import (
)
func ExampleCountAlnum() {
- fmt.Println(CountAlnum("// A b c 1 2 3"))
+ fmt.Println(CountAlnum(`// A b c 1 2 3`))
// Output: 6
}
func ExampleCountAlnumDistribution() {
- chars, counts := CountAlnumDistribution("// A b c A b")
- fmt.Printf("%c %v\n", chars, counts)
+ var (
+ chars []rune
+ counts []int
+ )
+
+ chars, counts = CountAlnumDistribution(`// A b c A b`)
+
+ fmt.Printf(`%c %v`, chars, counts)
// Output: [A b c] [2 2 1]
}
func ExampleCountCharSequence() {
- text := "aaa abcdee ffgf"
+ var (
+ text = `aaa abcdee ffgf`
+ chars []rune
+ counts []int
+ )
- chars, counts := CountCharSequence(text)
+ chars, counts = CountCharSequence(text)
// 'a' is not counted as 4 because its breaked by another character,
// space ' '.
- fmt.Printf("%c %v\n", chars, counts)
+ fmt.Printf(`%c %v`, chars, counts)
+
// Output:
// [a e f] [3 2 2]
}
func ExampleCountDigit() {
- text := "// Copyright 2018 Mhd Sulhan <ms@kilabit.info>. All rights reserved."
+ var text = `// Copyright 2018 Mhd Sulhan <ms@kilabit.info>. All rights reserved.`
fmt.Println(CountDigit(text))
// Output: 4
}
func ExampleCountUniqChar() {
- fmt.Println(CountUniqChar("abc abc"))
- fmt.Println(CountUniqChar("abc ABC"))
+ fmt.Println(CountUniqChar(`abc abc`))
+ fmt.Println(CountUniqChar(`abc ABC`))
// Output:
// 4
// 7
}
func ExampleCountUpperLower() {
- fmt.Println(CountUpperLower("// A B C d e f g h I J K"))
+ fmt.Println(CountUpperLower(`// A B C d e f g h I J K`))
// Output: 6 5
}
func ExampleMaxCharSequence() {
- c, n := MaxCharSequence("aaa abcdee ffgf")
+ var (
+ c rune
+ n int
+ )
+
+ c, n = MaxCharSequence(`aaa abcdee ffgf`)
- fmt.Printf("%c %d\n", c, n)
+ fmt.Printf(`%c %d`, c, n)
// Output: a 3
}
func ExampleRatioAlnum() {
- fmt.Println(RatioAlnum("//A1"))
+ fmt.Println(RatioAlnum(`//A1`))
// Output: 0.5
}
func ExampleRatioDigit() {
- fmt.Println(RatioDigit("// A b 0 1"))
+ fmt.Println(RatioDigit(`// A b 0 1`))
// Output: 0.2
}
func ExampleRatioNonAlnum() {
- fmt.Println(RatioNonAlnum("// A1", false))
- fmt.Println(RatioNonAlnum("// A1", true))
+ fmt.Println(RatioNonAlnum(`// A1`, false))
+ fmt.Println(RatioNonAlnum(`// A1`, true))
// Output:
// 0.4
// 0.6
}
func ExampleRatioUpper() {
- fmt.Println(RatioUpper("// A b c d"))
+ fmt.Println(RatioUpper(`// A b c d`))
// Output: 0.25
}
func ExampleRatioUpperLower() {
- fmt.Println(RatioUpperLower("// A b c d e"))
+ fmt.Println(RatioUpperLower(`// A b c d e`))
// Output: 0.25
}
func ExampleTextSumCountTokens() {
- text := "[[aa]] [[AA]]"
+ var (
+ text = `[[aa]] [[AA]]`
+ tokens = []string{`[[`}
+ )
- tokens := []string{"[["}
fmt.Println(TextSumCountTokens(text, tokens, false))
- tokens = []string{"aa"}
+ tokens = []string{`aa`}
fmt.Println(TextSumCountTokens(text, tokens, false))
fmt.Println(TextSumCountTokens(text, tokens, true))
@@ -103,10 +121,10 @@ func ExampleTextSumCountTokens() {
}
func ExampleTextFrequencyOfTokens() {
- text := "a b c d A B C D 1 2"
+ var text = `a b c d A B C D 1 2`
- fmt.Println(TextFrequencyOfTokens(text, []string{"a"}, false))
- fmt.Println(TextFrequencyOfTokens(text, []string{"a"}, true))
+ fmt.Println(TextFrequencyOfTokens(text, []string{`a`}, false))
+ fmt.Println(TextFrequencyOfTokens(text, []string{`a`}, true))
// Output:
// 0.2
// 0.1