2019-10-12 09:28:15 +03:00
|
|
|
/*
|
|
|
|
DESCRIPTION
|
|
|
|
gvctrl_test.go provides tests of functionality in the gvctrl package.
|
|
|
|
|
|
|
|
AUTHORS
|
|
|
|
Saxon A. Nelson-Milton <saxon@ausocean.org>
|
|
|
|
|
|
|
|
LICENSE
|
|
|
|
Copyright (C) 2019 the Australian Ocean Lab (AusOcean)
|
|
|
|
|
|
|
|
It is free software: you can redistribute it and/or modify them
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
in gpl.txt. If not, see http://www.gnu.org/licenses.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package gvctrl
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func TestClosestValIdx(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
l []int
|
|
|
|
v int
|
|
|
|
want int
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
l: []int{2, 5, 8, 11, 14},
|
|
|
|
v: 6,
|
|
|
|
want: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
l: []int{2, 5, 8, 11, 14},
|
|
|
|
v: 12,
|
|
|
|
want: 3,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
l: []int{2, 5, 8, 11, 14},
|
|
|
|
v: 13,
|
|
|
|
want: 4,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
l: []int{2, 5, 8, 11, 14},
|
|
|
|
v: 0,
|
|
|
|
want: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
l: []int{2, 5, 8, 11, 14},
|
|
|
|
v: 17,
|
|
|
|
want: 4,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
l: []int{2, 5, 8, 11, 15},
|
|
|
|
v: 13,
|
|
|
|
want: 3,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
l: []int{},
|
|
|
|
v: 17,
|
|
|
|
want: 0,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, test := range tests {
|
|
|
|
got := closestValIdx(test.v, test.l)
|
|
|
|
if got != test.want {
|
|
|
|
t.Errorf("did not get expected result for test: %d\nGot: %v\nWant: %v", i, got, test.want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-10-12 09:35:44 +03:00
|
|
|
|
|
|
|
func TestConvRate(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
l []int
|
|
|
|
v int
|
|
|
|
want string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
l: []int{512, 1024, 2048, 3072},
|
|
|
|
v: 1400,
|
|
|
|
want: "1024000",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
l: []int{512, 1024, 2048, 3072},
|
|
|
|
v: 1900,
|
|
|
|
want: "2048000",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
l: []int{512, 1024, 2048, 3072},
|
|
|
|
v: 4000,
|
|
|
|
want: "3072000",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, test := range tests {
|
|
|
|
got := convRate(test.v, test.l)
|
|
|
|
if got != test.want {
|
|
|
|
t.Errorf("did not get expected result for test: %d\nGot: %v\nWant: %v", i, got, test.want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|