Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warning with table.CountBetween #4

Open
SamuelMarks opened this issue Apr 1, 2019 · 2 comments
Open

warning with table.CountBetween #4

SamuelMarks opened this issue Apr 1, 2019 · 2 comments

Comments

@SamuelMarks
Copy link

SamuelMarks commented Apr 1, 2019

Many warnings appear, from use of this function:

cete/count_test.go

Lines 28 to 152 in 717790f

func testCounting(t *testing.T, compression bool) {
dir, err := ioutil.TempDir("", "cete_")
panicNotNil(err)
t.Log("testing directory:", dir)
defer func() {
if !t.Failed() {
os.RemoveAll(dir)
}
}()
db, err := Open(dir + "/data")
panicNotNil(err)
defer db.Close()
err = db.NewTable("count_testing", compression)
panicNotNil(err)
err = db.Table("count_testing").NewIndex("Age")
panicNotNil(err)
for i := 1; i <= 1000; i++ {
panicNotNil(db.Table("count_testing").Set(paddedItoa(i), Person{Age: i}))
}
if db.Table("count_testing").CountBetween(MinValue, "0010") != 10 {
t.Fatal("count should be 10, but isn't")
}
if db.Table("count_testing").CountBetween(MinValue, "0100") != 100 {
t.Fatal("count should be 100, but isn't")
}
if db.Table("count_testing").CountBetween("0901", MaxValue) != 100 {
t.Fatal("count should be 100, but isn't")
}
if db.Table("count_testing").CountBetween("0101", "0200") != 100 {
t.Fatal("count should be 100, but isn't")
}
if db.Table("count_testing").CountBetween("0100", "0010") != 0 {
t.Fatal("count should be 0, but isn't")
}
if db.Table("count_testing").CountBetween(MinValue, MaxValue) != 1000 {
t.Fatal("count should be 1000, but isn't")
}
if db.Table("count_testing").CountBetween(MaxValue, MinValue) != 0 {
t.Fatal("count should be 0, but isn't")
}
if db.Table("count_testing").CountBetween(MinValue, MinValue) != 0 {
t.Fatal("count should be 0, but isn't")
}
if db.Table("count_testing").CountBetween(MaxValue, MaxValue) != 0 {
t.Fatal("count should be 0, but isn't")
}
if db.Table("count_testing").CountBetween("99999999", MaxValue) != 0 {
t.Fatal("count should be 0, but isn't")
}
if db.Table("count_testing").CountBetween(0, MaxValue) != 0 {
t.Fatal("count should be 0, but isn't")
}
if db.Table("count_testing").CountBetween(MinValue, 0) != 0 {
t.Fatal("count should be 0, but isn't")
}
if db.Table("count_testing").Index("Age").CountBetween(MinValue, 10) != 10 {
t.Fatal("count should be 10, but isn't")
}
if db.Table("count_testing").Index("Age").CountBetween(MinValue, 100) != 100 {
t.Fatal("count should be 100, but isn't")
}
if db.Table("count_testing").Index("Age").CountBetween(901, MaxValue) != 100 {
t.Fatal("count should be 100, but isn't")
}
if db.Table("count_testing").Index("Age").CountBetween(101, 200) != 100 {
t.Fatal("count should be 100, but isn't")
}
if db.Table("count_testing").Index("Age").CountBetween(100, 10) != 0 {
t.Fatal("count should be 0, but isn't")
}
if db.Table("count_testing").Index("Age").CountBetween(MinValue, MaxValue) != 1000 {
t.Fatal("count should be 1000, but isn't")
}
if db.Table("count_testing").Index("Age").CountBetween(MaxValue, MinValue) != 0 {
t.Fatal("count should be 0, but isn't")
}
if db.Table("count_testing").Index("Age").CountBetween(MinValue, MinValue) != 0 {
t.Fatal("count should be 0, but isn't")
}
if db.Table("count_testing").Index("Age").CountBetween(MaxValue, MaxValue) != 0 {
t.Fatal("count should be 0, but isn't")
}
if db.Table("count_testing").Index("Age").CountBetween(10000, MaxValue) != 0 {
t.Fatal("count should be 0, but isn't")
}
countError := errors.New("cete testing: count error")
r := newRange(func() (string, []byte, uint64, error) {
return "", nil, 0, countError
}, func() {}, nil)
_, err = r.Count()
if err != countError {
t.Fatal("error should be countError, but isn't")
}
}

E.g.:

=== RUN   TestCounting
2019/04/01 16:51:38 table.go:627: cete: warning: lower and upper bounds of table.CountBetween must be a string or Bounds. A count of 0 has been returned instead
2019/04/01 16:51:38 table.go:618: cete: warning: lower and upper bounds of table.CountBetween must be a string or Bounds. A count of 0 has been returned instead
@1lann
Copy link
Owner

1lann commented Apr 1, 2019

This is intentional and part of these tests

cete/count_test.go

Lines 94 to 100 in 717790f

if db.Table("count_testing").CountBetween(0, MaxValue) != 0 {
t.Fatal("count should be 0, but isn't")
}
if db.Table("count_testing").CountBetween(MinValue, 0) != 0 {
t.Fatal("count should be 0, but isn't")
}

@SamuelMarks
Copy link
Author

Okay, maybe hide the warnings on test runs? - Because to the random developer it looks like failure, when it's an expected response.

You can also capture the stdout and stderr output, and assert that it equals what you expect.

@SamuelMarks SamuelMarks reopened this Apr 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants