From a0658b45aedac050ece1383131cf62e3ce252835 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Fri, 18 Sep 2020 09:24:23 -0400 Subject: [PATCH] miller/types/mlrval_functions_test.go iterate --- go/.vimrc | 1 + go/build | 1 + go/check | 15 +-- go/src/miller/types/mlrval_functions_test.go | 99 ++++++++++++++------ go/tester | 11 +++ go/todo.txt | 5 - 6 files changed, 87 insertions(+), 45 deletions(-) create mode 100755 go/tester diff --git a/go/.vimrc b/go/.vimrc index af46e1526..e992cc177 100644 --- a/go/.vimrc +++ b/go/.vimrc @@ -1,2 +1,3 @@ map \d :w:!clear;echo Building ...; echo; build-go map \f :w:!clear;echo Building ...; echo; build +map \t :w:!clear;echo; tester diff --git a/go/build b/go/build index 0d13d24dc..2d9461564 100755 --- a/go/build +++ b/go/build @@ -9,4 +9,5 @@ fi set -euo pipefail ./build-go +tester check $verbose diff --git a/go/check b/go/check index 02b729e1d..5145ef798 100755 --- a/go/check +++ b/go/check @@ -1,5 +1,9 @@ #!/bin/bash +# ================================================================ +# COMMAND-LINE TESTS +# ================================================================ + runner="bash" if [ "$1" = "-v" ]; then set -x @@ -8,17 +12,6 @@ fi set -euo pipefail -# ---------------------------------------------------------------- -# GO-SOURCE TESTS - -# go test -v ./... doesn't work since it triggers unready things in -# src/github.com/goccmack - -export GOPATH=$(pwd) -go test miller/types - -# ---------------------------------------------------------------- -# COMMAND-LINE TESTS $runner u/try-io > u/try-io.out $runner u/try-chain > u/try-chain.out $runner u/try-verbs > u/try-verbs.out diff --git a/go/src/miller/types/mlrval_functions_test.go b/go/src/miller/types/mlrval_functions_test.go index 9ff1c0f7f..ca97460c7 100644 --- a/go/src/miller/types/mlrval_functions_test.go +++ b/go/src/miller/types/mlrval_functions_test.go @@ -7,33 +7,15 @@ package types import ( "testing" - //"types" ) -// ---------------------------------------------------------------- -func TestLexicalAscendingComparator(t *testing.T) { - var a = MlrvalFromInt64(10) - var b = MlrvalFromInt64(2) - if LexicalAscendingComparator(&a, &b) != -1 { - t.Fatal() - } - - a = MlrvalFromString("abc") - b = MlrvalFromString("def") - if LexicalAscendingComparator(&a, &b) != -1 { - t.Fatal() - } - - a = MlrvalFromInt64(3) - b = MlrvalFromBool(true) - if LexicalAscendingComparator(&a, &b) != -1 { - t.Fatal() - } -} - // ---------------------------------------------------------------- // SORTING -// Sort rules (same for min, max, and comparator): +// +// Lexical compare is just string-sort on stringify of mlrvals: +// e.g. "hello" < "true". +// +// Numerical sort rules (same for min, max, and comparator): // * NUMERICS < BOOL < STRINGS < ERROR < ABSENT // * error == error (singleton type) // * absent == absent (singleton type) @@ -41,7 +23,8 @@ func TestLexicalAscendingComparator(t *testing.T) { // * numeric compares on numbers // * false < true -func TestNumericAscendingComparator(t *testing.T) { +func TestComparactors(t *testing.T) { + i10 := MlrvalFromInt64(10) i2 := MlrvalFromInt64(2) @@ -56,7 +39,28 @@ func TestNumericAscendingComparator(t *testing.T) { a := MlrvalFromAbsent() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Within-type comparisons + // Within-type lexical comparisons + if LexicalAscendingComparator(&i10, &i2) != -1 { + t.Fatal() + } + if LexicalAscendingComparator(&bfalse, &bfalse) != 0 { + t.Fatal() + } + if LexicalAscendingComparator(&bfalse, &btrue) != -1 { + t.Fatal() + } + if LexicalAscendingComparator(&sabc, &sdef) != -1 { + t.Fatal() + } + if LexicalAscendingComparator(&e, &e) != 0 { + t.Fatal() + } + if LexicalAscendingComparator(&a, &a) != 0 { + t.Fatal() + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // Within-type numeric comparisons if NumericAscendingComparator(&i10, &i2) != 1 { t.Fatal() } @@ -77,17 +81,54 @@ func TestNumericAscendingComparator(t *testing.T) { if NumericAscendingComparator(&a, &a) != 0 { t.Fatal() } - // xxx more // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Across-type comparisons + // Across-type lexical comparisons + + if LexicalAscendingComparator(&i10, &btrue) != -1 { // "10" < "true" + t.Fatal() + } + if LexicalAscendingComparator(&i10, &sabc) != -1 { // "10" < "abc" + t.Fatal() + } + if LexicalAscendingComparator(&i10, &e) != 1 { // "10" > "(error)" + t.Fatal() + } + + if LexicalAscendingComparator(&bfalse, &sabc) != 1 { // "false" > "abc" + t.Fatal() + } + if LexicalAscendingComparator(&bfalse, &e) != 1 { // "false" > "(error)" + t.Fatal() + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // Across-type numeric comparisons if NumericAscendingComparator(&i10, &btrue) != -1 { t.Fatal() } - if NumericAscendingComparator(&e, &a) != -1 { + if NumericAscendingComparator(&i10, &sabc) != -1 { + t.Fatal() + } + if NumericAscendingComparator(&i10, &e) != -1 { + t.Fatal() + } + if NumericAscendingComparator(&i10, &a) != -1 { t.Fatal() } - // xxx more + if NumericAscendingComparator(&bfalse, &sabc) != -1 { + t.Fatal() + } + if NumericAscendingComparator(&bfalse, &e) != -1 { + t.Fatal() + } + if NumericAscendingComparator(&bfalse, &a) != -1 { + t.Fatal() + } + + if NumericAscendingComparator(&e, &a) != -1 { + t.Fatal() + } } diff --git a/go/tester b/go/tester new file mode 100755 index 000000000..63c741b91 --- /dev/null +++ b/go/tester @@ -0,0 +1,11 @@ +#!/bin/bash + +# ================================================================ +# GO-SOURCE TESTS +# ================================================================ + +# go test -v ./... doesn't work since it triggers unready things in +# src/github.com/goccmack + +export GOPATH=$(pwd) +go test miller/types diff --git a/go/todo.txt b/go/todo.txt index 6731b2785..f580e54e3 100644 --- a/go/todo.txt +++ b/go/todo.txt @@ -2,14 +2,9 @@ TOP OF LIST: * go-try: - o rename: bulk-edit for b,i,x vs x,i,b cases - - ! sort - - UT per se for 'NUMERICS < BOOL < STRINGS < ERROR < ABSENT' ! filter ! emit; print/dump - ! quoted NIDX - how with whitespace regex -- ? ! quoted DKVP