gocollatz/collatz/calculator_test.go
Lars M. Rogne 99eeeedc65
All checks were successful
Run Tests / test (push) Successful in 25s
Improvements
2024-04-24 22:04:34 +02:00

46 lines
945 B
Go

package collatz
import (
"math/big"
"testing"
)
type MockParser struct {
value *big.Int
}
func (m *MockParser) Parse() (*big.Int, error) {
return m.value, nil
}
func TestNewCalculator(t *testing.T) {
parser := &MockParser{}
calculator := NewCalculator(parser)
if calculator.parser != parser {
t.Errorf("Expected parser to be %v, got %v", parser, calculator.parser)
}
if calculator.one.Cmp(big.NewInt(1)) != 0 {
t.Errorf("Expected one to be 1, got %v", calculator.one)
}
if calculator.two.Cmp(big.NewInt(2)) != 0 {
t.Errorf("Expected two to be 2, got %v", calculator.two)
}
if calculator.three.Cmp(big.NewInt(3)) != 0 {
t.Errorf("Expected three to be 3, got %v", calculator.three)
}
}
func TestCalculateCollatz(t *testing.T) {
parser := &MockParser{value: big.NewInt(6)}
calculator := NewCalculator(parser)
err := calculator.CalculateCollatz()
if err != nil {
t.Errorf("Expected no error, got %v", err)
}
}