aboutsummaryrefslogtreecommitdiff
path: root/lib/strings/statistic_example_test.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2018-09-17 00:26:46 +0700
committerShulhan <ms@kilabit.info>2018-09-17 22:51:23 +0700
commit66caeb368336e9f149d6f40772e7f0fdd070cf78 (patch)
treed0295d2fb895ce9e046400fae90cd7d69081c16a /lib/strings/statistic_example_test.go
parentf911fdc362d2a98a9f4deb93c18231ae77df12a1 (diff)
downloadpakakeh.go-66caeb368336e9f149d6f40772e7f0fdd070cf78.tar.xz
Merge package "github.com/shuLhan/tekstus", part 3/3
Diffstat (limited to 'lib/strings/statistic_example_test.go')
-rw-r--r--lib/strings/statistic_example_test.go113
1 files changed, 113 insertions, 0 deletions
diff --git a/lib/strings/statistic_example_test.go b/lib/strings/statistic_example_test.go
new file mode 100644
index 00000000..e3df7d56
--- /dev/null
+++ b/lib/strings/statistic_example_test.go
@@ -0,0 +1,113 @@
+// Copyright 2018, Shulhan <ms@kilabit.info>. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package strings
+
+import (
+ "fmt"
+)
+
+func ExampleCountAlnum() {
+ 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)
+ // Output: [A b c] [2 2 1]
+}
+
+func ExampleCountCharSequence() {
+ text := "aaa abcdee ffgf"
+
+ chars, counts := CountCharSequence(text)
+
+ // 'a' is not counted as 4 because its breaked by another character,
+ // space ' '.
+ fmt.Printf("%c %v\n", chars, counts)
+ // Output:
+ // [a e f] [3 2 2]
+}
+
+func ExampleCountDigit() {
+ 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"))
+ // Output:
+ // 4
+ // 7
+}
+
+func ExampleCountUpperLower() {
+ 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")
+
+ fmt.Printf("%c %d\n", c, n)
+ // Output: a 3
+}
+
+func ExampleRatioAlnum() {
+ fmt.Println(RatioAlnum("//A1"))
+ // Output: 0.5
+}
+
+func ExampleRatioDigit() {
+ fmt.Println(RatioDigit("// A b 0 1"))
+ // Output: 0.2
+}
+
+func ExampleRatioNonAlnum() {
+ fmt.Println(RatioNonAlnum("// A1", false))
+ fmt.Println(RatioNonAlnum("// A1", true))
+ // Output:
+ // 0.4
+ // 0.6
+}
+
+func ExampleRatioUpper() {
+ fmt.Println(RatioUpper("// A b c d"))
+ // Output: 0.25
+}
+
+func ExampleRatioUpperLower() {
+ fmt.Println(RatioUpperLower("// A b c d e"))
+ // Output: 0.25
+}
+
+func ExampleTextSumCountTokens() {
+ text := "[[aa]] [[AA]]"
+
+ tokens := []string{"[["}
+ fmt.Println(TextSumCountTokens(text, tokens, false))
+
+ tokens = []string{"aa"}
+ fmt.Println(TextSumCountTokens(text, tokens, false))
+
+ fmt.Println(TextSumCountTokens(text, tokens, true))
+
+ // Output:
+ // 2
+ // 2
+ // 1
+}
+
+func ExampleTextFrequencyOfTokens() {
+ 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))
+ // Output:
+ // 0.2
+ // 0.1
+}