Skip to content

Commit 54df21e

Browse files
author
oxe-i
committed
composition of functions in different lines
1 parent c916ce2 commit 54df21e

File tree

2 files changed

+45
-15
lines changed

2 files changed

+45
-15
lines changed

exercises/practice/word-count/WordCountTest.lean

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,68 @@ def wordCountTests : TestSuite :=
99
|>.addTest "count one word" (do
1010
return assertEqual [
1111
("word", 1)
12-
] ((·.mergeSort (λ (k1, _) (k2, _) => k1 ≤ k2)) <| Std.HashMap.toList <| WordCount.countWords "word"))
12+
] $ WordCount.countWords "word"
13+
|>.toList
14+
|>.mergeSort λ (k1, _) (k2, _) => k1 ≤ k2)
1315
|>.addTest "count one of each word" (do
1416
return assertEqual [
1517
("each", 1),
1618
("of", 1),
1719
("one", 1)
18-
] ((·.mergeSort (λ (k1, _) (k2, _) => k1 ≤ k2)) <| Std.HashMap.toList <| WordCount.countWords "one of each"))
20+
] $ WordCount.countWords "one of each"
21+
|>.toList
22+
|>.mergeSort λ (k1, _) (k2, _) => k1 ≤ k2)
1923
|>.addTest "multiple occurrences of a word" (do
2024
return assertEqual [
2125
("blue", 1),
2226
("fish", 4),
2327
("one", 1),
2428
("red", 1),
2529
("two", 1)
26-
] ((·.mergeSort (λ (k1, _) (k2, _) => k1 ≤ k2)) <| Std.HashMap.toList <| WordCount.countWords "one fish two fish red fish blue fish"))
30+
] $ WordCount.countWords "one fish two fish red fish blue fish"
31+
|>.toList
32+
|>.mergeSort λ (k1, _) (k2, _) => k1 ≤ k2)
2733
|>.addTest "handles cramped lists" (do
2834
return assertEqual [
2935
("one", 1),
3036
("three", 1),
3137
("two", 1)
32-
] ((·.mergeSort (λ (k1, _) (k2, _) => k1 ≤ k2)) <| Std.HashMap.toList <| WordCount.countWords "one,two,three"))
38+
] $ WordCount.countWords "one,two,three"
39+
|>.toList
40+
|>.mergeSort λ (k1, _) (k2, _) => k1 ≤ k2)
3341
|>.addTest "handles expanded lists" (do
3442
return assertEqual [
3543
("one", 1),
3644
("three", 1),
3745
("two", 1)
38-
] ((·.mergeSort (λ (k1, _) (k2, _) => k1 ≤ k2)) <| Std.HashMap.toList <| WordCount.countWords "one,\ntwo,\nthree"))
46+
] $ WordCount.countWords "one,\ntwo,\nthree"
47+
|>.toList
48+
|>.mergeSort λ (k1, _) (k2, _) => k1 ≤ k2)
3949
|>.addTest "ignore punctuation" (do
4050
return assertEqual [
4151
("as", 1),
4252
("car", 1),
4353
("carpet", 1),
4454
("java", 1),
4555
("javascript", 1)
46-
] ((·.mergeSort (λ (k1, _) (k2, _) => k1 ≤ k2)) <| Std.HashMap.toList <| WordCount.countWords "car: carpet as java: javascript!!&@$%^&"))
56+
] $ WordCount.countWords "car: carpet as java: javascript!!&@$%^&"
57+
|>.toList
58+
|>.mergeSort λ (k1, _) (k2, _) => k1 ≤ k2)
4759
|>.addTest "include numbers" (do
4860
return assertEqual [
4961
("1", 1),
5062
("2", 1),
5163
("testing", 2)
52-
] ((·.mergeSort (λ (k1, _) (k2, _) => k1 ≤ k2)) <| Std.HashMap.toList <| WordCount.countWords "testing, 1, 2 testing"))
64+
] $ WordCount.countWords "testing, 1, 2 testing"
65+
|>.toList
66+
|>.mergeSort λ (k1, _) (k2, _) => k1 ≤ k2)
5367
|>.addTest "normalize case" (do
5468
return assertEqual [
5569
("go", 3),
5670
("stop", 2)
57-
] ((·.mergeSort (λ (k1, _) (k2, _) => k1 ≤ k2)) <| Std.HashMap.toList <| WordCount.countWords "go Go GO Stop stop"))
71+
] $ WordCount.countWords "go Go GO Stop stop"
72+
|>.toList
73+
|>.mergeSort λ (k1, _) (k2, _) => k1 ≤ k2)
5874
|>.addTest "with apostrophes" (do
5975
return assertEqual [
6076
("cry", 1),
@@ -65,7 +81,9 @@ def wordCountTests : TestSuite :=
6581
("laugh", 1),
6682
("then", 1),
6783
("you're", 1)
68-
] ((·.mergeSort (λ (k1, _) (k2, _) => k1 ≤ k2)) <| Std.HashMap.toList <| WordCount.countWords "'First: don't laugh. Then: don't cry. You're getting it.'"))
84+
] $ WordCount.countWords "'First: don't laugh. Then: don't cry. You're getting it.'"
85+
|>.toList
86+
|>.mergeSort λ (k1, _) (k2, _) => k1 ≤ k2)
6987
|>.addTest "with quotations" (do
7088
return assertEqual [
7189
("and", 1),
@@ -74,7 +92,9 @@ def wordCountTests : TestSuite :=
7492
("joe", 1),
7593
("large", 2),
7694
("tell", 1)
77-
] ((·.mergeSort (λ (k1, _) (k2, _) => k1 ≤ k2)) <| Std.HashMap.toList <| WordCount.countWords "Joe can't tell between 'large' and large."))
95+
] $ WordCount.countWords "Joe can't tell between 'large' and large."
96+
|>.toList
97+
|>.mergeSort λ (k1, _) (k2, _) => k1 ≤ k2)
7898
|>.addTest "substrings from the beginning" (do
7999
return assertEqual [
80100
("a", 1),
@@ -85,23 +105,31 @@ def wordCountTests : TestSuite :=
85105
("can't", 1),
86106
("joe", 1),
87107
("tell", 1)
88-
] ((·.mergeSort (λ (k1, _) (k2, _) => k1 ≤ k2)) <| Std.HashMap.toList <| WordCount.countWords "Joe can't tell between app, apple and a."))
108+
] $ WordCount.countWords "Joe can't tell between app, apple and a."
109+
|>.toList
110+
|>.mergeSort λ (k1, _) (k2, _) => k1 ≤ k2)
89111
|>.addTest "multiple spaces not detected as a word" (do
90112
return assertEqual [
91113
("multiple", 1),
92114
("whitespaces", 1)
93-
] ((·.mergeSort (λ (k1, _) (k2, _) => k1 ≤ k2)) <| Std.HashMap.toList <| WordCount.countWords " multiple whitespaces"))
115+
] $ WordCount.countWords " multiple whitespaces"
116+
|>.toList
117+
|>.mergeSort λ (k1, _) (k2, _) => k1 ≤ k2)
94118
|>.addTest "alternating word separators not detected as a word" (do
95119
return assertEqual [
96120
("one", 1),
97121
("three", 1),
98122
("two", 1)
99-
] ((·.mergeSort (λ (k1, _) (k2, _) => k1 ≤ k2)) <| Std.HashMap.toList <| WordCount.countWords ",\n,one,\n ,two \n 'three'"))
123+
] $ WordCount.countWords ",\n,one,\n ,two \n 'three'"
124+
|>.toList
125+
|>.mergeSort λ (k1, _) (k2, _) => k1 ≤ k2)
100126
|>.addTest "quotation for word with apostrophe" (do
101127
return assertEqual [
102128
("can", 1),
103129
("can't", 2)
104-
] ((·.mergeSort (λ (k1, _) (k2, _) => k1 ≤ k2)) <| Std.HashMap.toList <| WordCount.countWords "can, can't, 'can't'"))
130+
] $ WordCount.countWords "can, can't, 'can't'"
131+
|>.toList
132+
|>.mergeSort λ (k1, _) (k2, _) => k1 ≤ k2)
105133

106134
def main : IO UInt32 := do
107135
runTestSuitesWithExitCode [wordCountTests]

generators/Generator/Generator/WordCountGenerator.lean

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ def genTestCase (exercise : String) (case : TreeMap.Raw String Json) : String :=
2323
let description := case.get! "description"
2424
|> (·.compress)
2525
let funName := getFunName (case.get! "property")
26-
let call := s!"((·.mergeSort (λ (k1, _) (k2, _) => k1 ≤ k2)) <| Std.HashMap.toList <| {exercise}.{funName} {insertAllInputs input})"
26+
let call := s!"$ {exercise}.{funName} {insertAllInputs input}
27+
|>.toList
28+
|>.mergeSort λ (k1, _) (k2, _) => k1 ≤ k2"
2729
s!"
2830
|>.addTest {description} (do
2931
return assertEqual {expected} {call})"

0 commit comments

Comments
 (0)