miller/types/mlrval_functions_test.go iterate

This commit is contained in:
John Kerl 2020-09-18 09:24:23 -04:00
parent 12fa4f63a1
commit a0658b45ae
6 changed files with 87 additions and 45 deletions

View file

@ -1,2 +1,3 @@
map \d :w<C-m>:!clear;echo Building ...; echo; build-go<C-m>
map \f :w<C-m>:!clear;echo Building ...; echo; build<C-m>
map \t :w<C-m>:!clear;echo; tester<C-m>

View file

@ -9,4 +9,5 @@ fi
set -euo pipefail
./build-go
tester
check $verbose

View file

@ -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

View file

@ -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()
}
}

11
go/tester Executable file
View file

@ -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

View file

@ -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