Skip to content

Commit

Permalink
Make SetContainer equality work like in C++
Browse files Browse the repository at this point in the history
  • Loading branch information
squeek502 committed Mar 19, 2017
1 parent e145a61 commit 38f5f33
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/bindings/SetContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ namespace BWAPI_Lua
userType.set("erase", sol::resolve<SetClass::size_type(const ContainedClass&)>(&SetClass::erase));
userType.set("clear", &SetClass::clear);
userType.set(sol::meta_function::length, &SetClass::size);
userType.set(sol::meta_function::equal_to, [](const SetClass& a, const SetClass& b) { return a == b; });
return userType;
}
}
14 changes: 14 additions & 0 deletions tests/TestBindings/Lua/TestSetContainer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,17 @@ function clear()
set:clear()
assert(#set == 0)
end

-- sets are equal if they are of the same type and have the same contents
function equality()
local set1 = BWAPI.UnitTypeset({BWAPI.UnitTypes.Terran_SCV, BWAPI.UnitTypes.Terran_Firebat})
local set2 = BWAPI.UnitTypeset({BWAPI.UnitTypes.Terran_Firebat, BWAPI.UnitTypes.Terran_SCV})
local set3 = BWAPI.UnitTypeset({BWAPI.UnitTypes.Terran_Marine})
local set4 = BWAPI.DamageTypeset()

assert(set1 == set1)
assert(set1 == set2)
assert(set1 ~= set3)
assert(set2 ~= set3)
assert(set4 ~= set1)
end
7 changes: 7 additions & 0 deletions tests/TestBindings/TestSetContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,11 @@ TEST_CASE("setcontainer bindings", "[setcontainer]")
REQUIRE_NOTHROW(test());
}

SECTION("equality")
{
bindDamageType(lua["BWAPI"]);
sol::function test = lua["equality"];
REQUIRE_NOTHROW(test());
}

}

0 comments on commit 38f5f33

Please sign in to comment.