You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
935 B
Go
29 lines
935 B
Go
5 years ago
|
package bucket
|
||
|
|
||
|
import "testing"
|
||
|
|
||
|
func TestPour(t *testing.T) {
|
||
|
var testcases = []struct {
|
||
|
source *Bucket
|
||
|
target *Bucket
|
||
|
expectedSrcVol uint64
|
||
|
expectedTargetVol uint64
|
||
|
}{
|
||
|
{&Bucket{Capacity: 5, Volume: 2}, &Bucket{Capacity: 3, Volume: 2}, 1, 3},
|
||
|
{&Bucket{Capacity: 5, Volume: 1}, &Bucket{Capacity: 3, Volume: 1}, 0, 2},
|
||
|
{&Bucket{Capacity: 5, Volume: 0}, &Bucket{Capacity: 3, Volume: 0}, 0, 0},
|
||
|
{&Bucket{Capacity: 5, Volume: 5}, &Bucket{Capacity: 3, Volume: 3}, 5, 3},
|
||
|
{&Bucket{Capacity: 5, Volume: 4}, &Bucket{Capacity: 3, Volume: 2}, 3, 3},
|
||
|
}
|
||
|
|
||
|
for _, tc := range testcases {
|
||
|
tc.source.Pour(tc.target)
|
||
|
if tc.source.Volume != tc.expectedSrcVol {
|
||
|
t.Errorf("expected source volume %d, got = %d", tc.expectedSrcVol, tc.source.Volume)
|
||
|
}
|
||
|
if tc.target.Volume != tc.expectedTargetVol {
|
||
|
t.Errorf("expected target volume %d, got = %d", tc.expectedTargetVol, tc.target.Volume)
|
||
|
}
|
||
|
}
|
||
|
}
|