2019-09-23 09:05:19 +01:00
|
|
|
/*
|
|
|
|
Pominal
|
2020-02-11 16:27:47 +00:00
|
|
|
Copyright (C) 2020 Daniel Anglin
|
2019-09-23 09:05:19 +01:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it 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.
|
|
|
|
|
|
|
|
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-09-20 00:55:10 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-09-23 09:05:19 +01:00
|
|
|
"reflect"
|
2019-09-20 00:55:10 +01:00
|
|
|
"testing"
|
2020-01-20 09:13:47 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/rivo/tview"
|
2019-09-20 00:55:10 +01:00
|
|
|
)
|
|
|
|
|
2020-01-18 01:04:51 +00:00
|
|
|
// TestNewPominal validates the factory function for generating new
|
2020-02-13 12:42:55 +00:00
|
|
|
// Pominal values from PominalConfig values.
|
2019-09-23 09:05:19 +01:00
|
|
|
func TestNewPominal(t *testing.T) {
|
2020-01-20 09:13:47 +00:00
|
|
|
t.Log("Given the need to test the creation of a new Pominal instance.")
|
2020-01-18 01:04:51 +00:00
|
|
|
{
|
2020-01-20 09:13:47 +00:00
|
|
|
for _, p := range newPominalTestCases {
|
2020-01-18 01:04:51 +00:00
|
|
|
testFunc := func(t *testing.T) {
|
|
|
|
t.Log(p.description)
|
2020-02-13 12:42:55 +00:00
|
|
|
res, err := newPominal(p.config)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%s\tError while creating the Pominal value, %s", failure, err.Error())
|
|
|
|
}
|
2020-01-18 01:04:51 +00:00
|
|
|
if !reflect.DeepEqual(res, p.expectedPominal) {
|
2020-02-13 12:42:55 +00:00
|
|
|
t.Errorf("%s\tUnexpected Pominal value created. Expected %v, received %v.", failure, p.expectedPominal, res)
|
2020-01-18 01:04:51 +00:00
|
|
|
} else {
|
|
|
|
t.Logf("%s\tTest passed.", success)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
t.Run(p.name, testFunc)
|
2019-09-20 00:55:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-20 09:13:47 +00:00
|
|
|
|
|
|
|
// TestRun validates the Pominal runtime. This test creates a new
|
|
|
|
// Pominal instance and executes the runtime in a separate goroutine.
|
|
|
|
// To ease testing the work, short break and long break timers are equal.
|
|
|
|
// Before the sub-tests are run there is a second delay to allow the
|
|
|
|
// runtime to initialise. The test then checks that the correct
|
|
|
|
// session label, work session number and pominal cycle number
|
|
|
|
// are set for each session. This test runs for exactly one
|
|
|
|
// pominal cycle.
|
|
|
|
func TestRun(t *testing.T) {
|
2020-02-13 12:42:55 +00:00
|
|
|
config, err := newPominalConfig("", "1m", "1m", "1m", 2)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%s\tError while creating the PominalConfig value, %s", failure, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
pominal, err := newPominal(config)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("%s\tError while creating the Pominal value, %s", failure, err.Error())
|
|
|
|
}
|
|
|
|
|
2020-01-20 09:13:47 +00:00
|
|
|
defer pominal.Stop()
|
|
|
|
|
|
|
|
// create the most basic text view for the info and timer
|
|
|
|
// views since we are not testing the user interface.
|
|
|
|
infoUI := tview.NewTextView()
|
|
|
|
timerUI := tview.NewTextView()
|
|
|
|
|
|
|
|
go pominal.Run(infoUI, timerUI)
|
|
|
|
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
|
|
|
|
t.Log("Given the need to test the Pominal runtime execution.")
|
|
|
|
{
|
|
|
|
for _, s := range sessionsTestCases {
|
|
|
|
testFunc := func(t *testing.T) {
|
|
|
|
t.Log(s.description)
|
|
|
|
if pominal.workSession != s.expectedWorkSession {
|
|
|
|
t.Errorf("%s\tUnexpected work session integer returned: expected %d, got %d", failure, s.expectedWorkSession, pominal.workSession)
|
|
|
|
} else {
|
|
|
|
t.Logf("%s\tExpected work session integer returned.", success)
|
|
|
|
}
|
|
|
|
if pominal.cycle != s.expectedCycle {
|
|
|
|
t.Errorf("%s\tUnexpected pominal cycle integer returned: expected %d, got %d", failure, s.expectedCycle, pominal.cycle)
|
|
|
|
} else {
|
|
|
|
t.Logf("%s\tExpected pominal cycle integer returned.", success)
|
|
|
|
}
|
|
|
|
if pominal.label != s.expectedLabel {
|
|
|
|
t.Errorf("%s\tUnexpected session label returned: expected %s, got %s", failure, s.expectedLabel, pominal.label)
|
|
|
|
} else {
|
|
|
|
t.Logf("%s\tExpected session label returned.", success)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
t.Run(s.name, testFunc)
|
|
|
|
time.Sleep(65 * time.Second)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|