Execute a Markov algorithm: Difference between revisions

→‎{{header|Go}}: Clarified output, showed portion of data file. (Markov algorithm code unchanged.)
(→‎{{header|Go}}: Clarified output, showed portion of data file. (Markov algorithm code unchanged.))
Line 959:
 
func main() {
fmt.Println("validating", len(testSet), "test cases")
var failures bool
for i, tc := range testSet {
if r := ma(tc.ruleSet, tc.sample); r != tc.output {
fmt.Println("test", i+1, "fail")
failures = true
}
}
if !failures {
fmt.Println("no failures")
}
}
Line 1,030 ⟶ 1,036:
return s
}</lang>
The rule set source file contains all the strings as literals, packaged into a data structure. It starts like this,
<lang go>
package main
 
func init() {
testSet = []testCase{
{
`# This rules file is extracted from Wikipedia:
# http://en.wikipedia.org/wiki/Markov_Algorithm
A -> apple
B -> bag
S -> shop
T -> the
the shop -> my brother
a never used -> .terminating rule`,
"I bought a B of As from T S.",
"I bought a bag of apples from my brother."},
{
`# Slightly modified from the rules on Wikipedia
A -> apple
B -> bag
...
</lang>
Compile both files, link, and run. Output:
<pre>
validating 5 test cases
no failures
</pre>
 
=={{header|Haskell}}==
1,707

edits