2016-04-01 15:19:07 -07:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
2017-03-23 17:51:50 -07:00
|
|
|
"fmt"
|
2016-04-01 15:19:07 -07:00
|
|
|
"testing"
|
2017-02-22 14:30:50 -08:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2016-04-01 15:19:07 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCoins(t *testing.T) {
|
2017-03-23 17:51:50 -07:00
|
|
|
assert := assert.New(t)
|
2017-02-22 14:30:50 -08:00
|
|
|
|
|
|
|
//Define the coins to be used in tests
|
|
|
|
good := Coins{
|
2016-04-01 15:19:07 -07:00
|
|
|
Coin{"GAS", 1},
|
|
|
|
Coin{"MINERAL", 1},
|
|
|
|
Coin{"TREE", 1},
|
|
|
|
}
|
2017-02-22 14:30:50 -08:00
|
|
|
neg := good.Negative()
|
|
|
|
sum := good.Plus(neg)
|
|
|
|
empty := Coins{
|
|
|
|
Coin{"GOLD", 0},
|
2016-04-01 15:19:07 -07:00
|
|
|
}
|
2017-02-22 14:30:50 -08:00
|
|
|
badSort1 := Coins{
|
2016-04-01 15:19:07 -07:00
|
|
|
Coin{"TREE", 1},
|
|
|
|
Coin{"GAS", 1},
|
|
|
|
Coin{"MINERAL", 1},
|
|
|
|
}
|
2017-02-22 14:30:50 -08:00
|
|
|
badSort2 := Coins{ // both are after the first one, but the second and third are in the wrong order
|
2017-01-31 03:24:49 -08:00
|
|
|
Coin{"GAS", 1},
|
|
|
|
Coin{"TREE", 1},
|
|
|
|
Coin{"MINERAL", 1},
|
|
|
|
}
|
2017-02-22 14:30:50 -08:00
|
|
|
badAmt := Coins{
|
2016-04-01 15:19:07 -07:00
|
|
|
Coin{"GAS", 1},
|
|
|
|
Coin{"TREE", 0},
|
|
|
|
Coin{"MINERAL", 1},
|
|
|
|
}
|
2017-02-22 14:30:50 -08:00
|
|
|
dup := Coins{
|
2016-04-01 15:19:07 -07:00
|
|
|
Coin{"GAS", 1},
|
|
|
|
Coin{"GAS", 1},
|
|
|
|
Coin{"MINERAL", 1},
|
|
|
|
}
|
|
|
|
|
2017-03-23 17:51:50 -07:00
|
|
|
assert.True(good.IsValid(), "Coins are valid")
|
|
|
|
assert.True(good.IsPositive(), fmt.Sprintf("Expected coins to be positive: %v", good))
|
|
|
|
assert.True(good.IsGTE(empty), fmt.Sprintf("Expected %v to be >= %v", good, empty))
|
|
|
|
assert.False(neg.IsPositive(), fmt.Sprintf("Expected neg coins to not be positive: %v", neg))
|
|
|
|
assert.Zero(len(sum), "Expected 0 coins")
|
|
|
|
assert.False(badSort1.IsValid(), "Coins are not sorted")
|
|
|
|
assert.False(badSort2.IsValid(), "Coins are not sorted")
|
|
|
|
assert.False(badAmt.IsValid(), "Coins cannot include 0 amounts")
|
|
|
|
assert.False(dup.IsValid(), "Duplicate coin")
|
2017-02-22 14:30:50 -08:00
|
|
|
|
2016-04-01 15:19:07 -07:00
|
|
|
}
|