diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | fmt.go | 34 | ||||
| -rw-r--r-- | go.mod | 3 | ||||
| -rwxr-xr-x | test | 6 |
4 files changed, 8 insertions, 36 deletions
@@ -1,2 +1 @@ markov -fmt @@ -1,34 +0,0 @@ -// This program wraps its input into short lines. It is based on fmt.awk from "The -// Practice of Programming" by Brian Kernighan and Rob Pike (pp. 229). -package main - -import ( - "bufio" - "fmt" - "os" -) - -const maxWidth = 80 // maximum number of characters per line - -func main() { - input := bufio.NewScanner(os.Stdin) - input.Split(bufio.ScanWords) - width := 0 - for input.Scan() { - word := input.Text() - - if width+1+len(word) > maxWidth { - fmt.Println() - width = 0 - } - - if width == 0 { - fmt.Print(word) - width += len(word) - } else { - fmt.Printf(" %s", word) - width += 1 + len(word) - } - } - fmt.Println() -} @@ -0,0 +1,3 @@ +module git.samanthony.xyz/markov + +go 1.25.8 @@ -1,4 +1,6 @@ -#!/usr/bin/sh +#!/bin/sh + +set -e # Check boundary conditions with small files. Output should match input. for f in empty a ab abc abcd; do @@ -20,3 +22,5 @@ rm out # Check that the output has a similar ratio of c's and d's to test randomness of # suffix selection. ./markov <tests/stats | freq -c | awk -f tests/stats.awk + +echo ok |