av/bitrate/BitrateCalculator_test.go

78 lines
2.4 KiB
Go
Raw Normal View History

2017-12-06 05:23:22 +03:00
/*
NAME
2017-12-06 06:11:32 +03:00
BitrateCalculator_test.go - is a file that may be used to test the
BitrateCalculator.go file using the golang testing utilities
2017-12-06 05:23:22 +03:00
DESCRIPTION
See Readme.md
AUTHOR
2017-12-06 06:11:32 +03:00
Saxon Nelson-Milton <saxon.milton@gmail.com>
2017-12-06 05:23:22 +03:00
LICENSE
2017-12-06 06:11:32 +03:00
BitrateCalculator_test.go is Copyright (C) 2017 the Australian Ocean Lab (AusOcean)
2017-12-06 05:23:22 +03:00
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
along with revid in gpl.txt. If not, see [GNU licenses](http://www.gnu.org/licenses).
*/
2017-12-05 13:16:26 +03:00
package bitrate
import (
2017-12-06 05:23:22 +03:00
"testing"
"time"
)
// Some consts used over duration of testing
const (
bitrateDelay1 = 0 // s
bitrateDelay2 = 5 // s
amountOfData = 100000.0
testTime = 2500.0 // ms
2017-12-05 13:16:26 +03:00
)
2017-12-06 05:23:22 +03:00
// This will be the BitrateCalculator object we use over testing
var bitrateCalc BitrateCalculator
// Simple test to check that the calculator can calc bitrate over a given
// duration of time
func Test1(t *testing.T) {
2017-12-06 06:11:32 +03:00
bitrateCalc = BitrateCalculator{}
2017-12-06 05:23:22 +03:00
bitrateCalc.Start(bitrateDelay1)
time.Sleep(testTime * time.Millisecond)
currentBitrate := int64(bitrateCalc.Stop(amountOfData))
2017-12-06 06:11:32 +03:00
actualBitrate := int64(amountOfData / ((testTime * time.Millisecond) / 1e9))
2017-12-06 05:23:22 +03:00
if currentBitrate != actualBitrate {
t.Errorf("Bitrate is wrong! Calculated: %v Actual %v", currentBitrate, actualBitrate)
}
}
// Now let's check that the output delay feature works
2017-12-06 06:11:32 +03:00
func Test2(t *testing.T) {
bitrateCalc = BitrateCalculator{}
var currentBitrate int64
2017-12-06 06:11:32 +03:00
for i := 0; i < 2; i++ {
bitrateCalc.Start(bitrateDelay2)
time.Sleep(testTime * time.Millisecond)
currentBitrate = int64(bitrateCalc.Stop(amountOfData))
if i == 0 && currentBitrate != 0 {
t.Errorf("The bitrate calc did not delay outputting!")
}
time.Sleep(6000 * time.Millisecond)
}
actualBitrate := int64(amountOfData / ((testTime * time.Millisecond) / 1e9))
if currentBitrate != actualBitrate {
t.Errorf("Bitrate is wrong! Calculated: %v Actual %v", currentBitrate, actualBitrate)
}
2017-12-06 05:23:22 +03:00
}