Filling in Accumulator
implementation and test client
as well as fixing the Canvas implementation so that it doesn't pop up an X window on init.
This commit is contained in:
34
algs4/src/go/algs4-test-accumulator/main.go
Normal file
34
algs4/src/go/algs4-test-accumulator/main.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/meatballhat/box-o-sand/algs4/src/go/algs4"
|
||||
)
|
||||
|
||||
func die(err error) {
|
||||
fmt.Fprintf(os.Stderr, "ERROR: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
die(errors.New("We need an int!"))
|
||||
}
|
||||
|
||||
nValues, err := strconv.Atoi(os.Args[1])
|
||||
if err != nil {
|
||||
die(err)
|
||||
}
|
||||
|
||||
a := algs4.NewAccumulator()
|
||||
for t := 0; t < nValues; t++ {
|
||||
a.AddDataValue(algs4.Random())
|
||||
}
|
||||
|
||||
fmt.Println(a)
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user