av/cmd/rv/probe_test.go

70 lines
1.9 KiB
Go
Raw Permalink Normal View History

/*
DESCRIPTION
Testing function for turbidity probe.
AUTHORS
Russell Stanley <russell@ausocean.org>
LICENSE
Copyright (C) 2021-2022 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 main
import (
"io"
2022-01-10 06:47:52 +03:00
"io/ioutil"
"testing"
"time"
"bitbucket.org/ausocean/utils/logger"
"gopkg.in/natefinch/lumberjack.v2"
2022-01-10 06:47:52 +03:00
)
// TestProbe reads a given video file and writes the sharpness and contrast scores to a turbidity probe.
2022-01-11 07:05:53 +03:00
func TestProbe(t *testing.T) {
// Create lumberjack logger.
fileLog := &lumberjack.Logger{
Filename: logPath,
MaxSize: logMaxSize,
MaxBackups: logMaxBackup,
MaxAge: logMaxAge,
}
log := logger.New(logVerbosity, io.MultiWriter(fileLog), logSuppress)
updatedMatrix := []float64{-0.2731048063, -0.0020501869, 661.0275911942, 0.0014327789, -0.2699443748, 339.3921028016, 0.0000838317, 0.0000476486, 1.0}
ts, err := NewTurbidityProbe(*log, time.Microsecond)
if err != nil {
t.Fatalf("failed to create turbidity probe")
}
err = ts.Update(updatedMatrix)
if err != nil {
t.Fatalf("could not update probe: %v", err)
}
2022-01-11 07:05:53 +03:00
video, err := ioutil.ReadFile("logo.h264")
2022-01-10 06:47:52 +03:00
if err != nil {
2022-01-11 07:05:53 +03:00
t.Fatalf("failed to read file: %v", err)
2022-01-10 06:47:52 +03:00
}
2022-01-11 07:05:53 +03:00
_, err = ts.Write(video)
2022-01-10 06:47:52 +03:00
if err != nil {
2022-01-11 07:05:53 +03:00
t.Fatalf("failed to write sharpness and contrast: %v", err)
2022-01-10 06:47:52 +03:00
}
2022-01-11 07:05:53 +03:00
t.Logf("contrast: %v, sharpness: %v\n", ts.contrast, ts.sharpness)
}