|
@@ -11,29 +11,39 @@ describe('EnumerableSet', function () {
|
|
|
this.set = await EnumerableSetMock.new();
|
|
|
});
|
|
|
|
|
|
+ async function expectMembersMatch (set, members) {
|
|
|
+ await Promise.all(members.map(async account =>
|
|
|
+ expect(await set.contains(account)).to.equal(true)
|
|
|
+ ));
|
|
|
+
|
|
|
+ expect(await set.enumerate()).to.have.same.members(members);
|
|
|
+
|
|
|
+ expect(await set.length()).to.bignumber.equal(members.length.toString());
|
|
|
+
|
|
|
+ expect(await Promise.all([...Array(members.length).keys()].map(index =>
|
|
|
+ set.get(index)
|
|
|
+ ))).to.have.same.members(members);
|
|
|
+ }
|
|
|
+
|
|
|
it('starts empty', async function () {
|
|
|
expect(await this.set.contains(accountA)).to.equal(false);
|
|
|
- expect(await this.set.enumerate()).to.have.same.members([]);
|
|
|
+
|
|
|
+ await expectMembersMatch(this.set, []);
|
|
|
});
|
|
|
|
|
|
it('adds a value', async function () {
|
|
|
const receipt = await this.set.add(accountA);
|
|
|
expectEvent(receipt, 'TransactionResult', { result: true });
|
|
|
|
|
|
- expect(await this.set.contains(accountA)).to.equal(true);
|
|
|
- expect(await this.set.enumerate()).to.have.same.members([ accountA ]);
|
|
|
+ await expectMembersMatch(this.set, [accountA]);
|
|
|
});
|
|
|
|
|
|
it('adds several values', async function () {
|
|
|
await this.set.add(accountA);
|
|
|
await this.set.add(accountB);
|
|
|
|
|
|
- expect(await this.set.contains(accountA)).to.equal(true);
|
|
|
- expect(await this.set.contains(accountB)).to.equal(true);
|
|
|
-
|
|
|
+ await expectMembersMatch(this.set, [accountA, accountB]);
|
|
|
expect(await this.set.contains(accountC)).to.equal(false);
|
|
|
-
|
|
|
- expect(await this.set.enumerate()).to.have.same.members([ accountA, accountB ]);
|
|
|
});
|
|
|
|
|
|
it('returns false when adding elements already in the set', async function () {
|
|
@@ -42,7 +52,7 @@ describe('EnumerableSet', function () {
|
|
|
const receipt = (await this.set.add(accountA));
|
|
|
expectEvent(receipt, 'TransactionResult', { result: false });
|
|
|
|
|
|
- expect(await this.set.enumerate()).to.have.same.members([ accountA ]);
|
|
|
+ await expectMembersMatch(this.set, [accountA]);
|
|
|
});
|
|
|
|
|
|
it('removes added values', async function () {
|
|
@@ -52,7 +62,7 @@ describe('EnumerableSet', function () {
|
|
|
expectEvent(receipt, 'TransactionResult', { result: true });
|
|
|
|
|
|
expect(await this.set.contains(accountA)).to.equal(false);
|
|
|
- expect(await this.set.enumerate()).to.have.same.members([]);
|
|
|
+ await expectMembersMatch(this.set, []);
|
|
|
});
|
|
|
|
|
|
it('returns false when removing elements not in the set', async function () {
|
|
@@ -99,10 +109,8 @@ describe('EnumerableSet', function () {
|
|
|
|
|
|
// [A, C]
|
|
|
|
|
|
- expect(await this.set.contains(accountA)).to.equal(true);
|
|
|
- expect(await this.set.contains(accountB)).to.equal(false);
|
|
|
- expect(await this.set.contains(accountC)).to.equal(true);
|
|
|
+ await expectMembersMatch(this.set, [accountA, accountC]);
|
|
|
|
|
|
- expect(await this.set.enumerate()).to.have.same.members([ accountA, accountC ]);
|
|
|
+ expect(await this.set.contains(accountB)).to.equal(false);
|
|
|
});
|
|
|
});
|