av/input/gvctrl/gvctrl_test.go

151 lines
2.8 KiB
Go
Raw Normal View History

/*
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 (
"errors"
"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)
}
}
}
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)
}
}
}
func TestHeight(t *testing.T) {
tests := []struct {
h int
want settings
err error
}{
{
h: 256,
want: settings{res: "4480256"},
},
{
h: 360,
want: settings{res: "6400360"},
},
{
h: 720,
want: settings{res: "12800720"},
},
{
h: 500,
want: settings{},
err: errors.New(""),
},
}
for i, test := range tests {
s := settings{}
got, err := Height(test.h)(s)
if test.err == nil && err != nil || test.err != nil && err == nil {
t.Errorf("did not get expected error: %v", test.err)
}
if got != test.want {
t.Errorf("did not get expected result for test: %d\nGot: %v\nWant: %v", i, got, test.want)
}
}
}