add more tests

master
kevin 4 years ago
parent d12e25a886
commit 68e46cf6b3

@ -72,12 +72,9 @@ func TestContainer(t *testing.T) {
{ {
act: actionDel, act: actionDel,
key: "first", key: "first",
val: "a",
}, },
}, },
expect: []string{ expect: []string{"b"},
"b",
},
}, },
{ {
name: "add two, delete two", name: "add two, delete two",
@ -95,38 +92,101 @@ func TestContainer(t *testing.T) {
{ {
act: actionDel, act: actionDel,
key: "first", key: "first",
},
{
act: actionDel,
key: "second",
},
},
expect: []string{},
},
{
name: "add three, dup values, delete two",
do: []action{
{
act: actionAdd,
key: "first",
val: "a", val: "a",
}, },
{
act: actionAdd,
key: "second",
val: "b",
},
{
act: actionAdd,
key: "third",
val: "a",
},
{
act: actionDel,
key: "first",
},
{ {
act: actionDel, act: actionDel,
key: "second", key: "second",
},
},
expect: []string{"a"},
},
{
name: "add three, dup values, delete two, delete not added",
do: []action{
{
act: actionAdd,
key: "first",
val: "a",
},
{
act: actionAdd,
key: "second",
val: "b", val: "b",
}, },
{
act: actionAdd,
key: "third",
val: "a",
},
{
act: actionDel,
key: "first",
},
{
act: actionDel,
key: "second",
},
{
act: actionDel,
key: "forth",
},
}, },
expect: []string{}, expect: []string{"a"},
}, },
} }
exclusives := []bool{true, false}
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(t *testing.T) { for _, exclusive := range exclusives {
c := newContainer(false) t.Run(test.name, func(t *testing.T) {
for _, order := range test.do { c := newContainer(exclusive)
if order.act == actionAdd { for _, order := range test.do {
c.OnAdd(internal.KV{ if order.act == actionAdd {
Key: order.key, c.OnAdd(internal.KV{
Val: order.val, Key: order.key,
}) Val: order.val,
} else { })
c.OnDelete(internal.KV{ } else {
Key: order.key, c.OnDelete(internal.KV{
Val: order.val, Key: order.key,
}) Val: order.val,
})
}
} }
} assert.True(t, c.dirty.True())
assert.True(t, c.dirty.True()) assert.ElementsMatch(t, test.expect, c.getValues())
assert.ElementsMatch(t, test.expect, c.getValues()) assert.False(t, c.dirty.True())
assert.False(t, c.dirty.True()) assert.ElementsMatch(t, test.expect, c.getValues())
assert.ElementsMatch(t, test.expect, c.getValues()) })
}) }
} }
} }

Loading…
Cancel
Save