Add methods for Bucket structs
parent
af8e7ebedb
commit
0943ed42dd
@ -0,0 +1,28 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue