Module:Reward/testcases

local Reward = require 'Module:Reward' local suite = require 'Module:ScribuntoUnit':new

function suite:testNormalize suite:assertEquals(nil, Reward.normalize) suite:assertEquals(nil, Reward.normalize(0)) suite:assertEquals(nil, Reward.normalize('[]')) suite:assertDeepEquals({}, Reward.normalize {})

suite:assertDeepEquals(, Reward.normalize {hero = 'a', rarity = 4}) suite:assertDeepEquals(, Reward.normalize {hero = 'a', fbrank = 'C'}) suite:assertDeepEquals(, Reward.normalize {seal = 'a'}) suite:assertDeepEquals(, Reward.normalize {accessory = 'a'}) suite:assertDeepEquals(, Reward.normalize {kind = 'a'}) suite:assertDeepEquals(, Reward.normalize {kind = 'a', count = 3})

suite:assertDeepEquals({{kind = 'a', count = 1}, {kind = 'a', count = 1}, {kind = 'a', count = 1}}, Reward.normalize {{kind = 'a'}, {kind = 'a'}, {kind = 'a'}}) end

function suite:testCompare local r0 = {} local r1 = Reward.normalize {seal = 'a'} local r2 = Reward.normalize {{seal = 'a'}, {seal = 'a'}} local r3 = Reward.normalize {{seal = 'a'}, {seal = 'b'}} local r4 = Reward.normalize {{seal = 'b'}, {seal = 'b'}} local r5 = Reward.normalize {{seal = 'b'}, {seal = 'a'}}

suite:assertEquals(0, Reward.compare(r1, r1)) suite:assertEquals(1, Reward.compare(r1, r0)) suite:assertEquals(-1, Reward.compare(r0, r1)) suite:assertEquals(-1, Reward.compare(r1, r2)) suite:assertEquals(1, Reward.compare(r2, r1)) suite:assertEquals(-1, Reward.compare(r1, r3)) suite:assertEquals(1, Reward.compare(r3, r1)) suite:assertEquals(nil, Reward.compare(r1, r4)) suite:assertEquals(nil, Reward.compare(r4, r1)) suite:assertEquals(0, Reward.compare(r3, r5))

r1 = Reward.normalize {kind = 'a'} r2 = Reward.normalize {kind = 'a', count = 3} r3 = Reward.normalize {kind = 'b', count = 2} r4 = Reward.normalize {{kind = 'a', count = 2}, {kind = 'a'}}

suite:assertEquals(-1, Reward.compare(r1, r2)) suite:assertEquals(nil, Reward.compare(r1, r3)) suite:assertEquals(0, Reward.compare(r2, r4))

r1 = Reward.normalize {{kind = 'a', count = 2}, {kind = 'b', count = 3}} r2 = Reward.normalize {{kind = 'b', count = 2}, {kind = 'a', count = 1}}

suite:assertEquals(1, Reward.compare(r1, r2)) suite:assertEquals(-1, Reward.compare(r2, r1)) suite:assertEquals(1, Reward.compare(r1, r3)) suite:assertEquals(1, Reward.compare(r2, r3)) suite:assertEquals(nil, Reward.compare(r1, r4)) end

function suite:testBest local t = { Reward.normalize {kind = 'a'}, Reward.normalize {kind = 'b'}, }	suite:assertEquals(nil, Reward.best(t))

t = { Reward.normalize {kind = 'a'}, Reward.normalize {kind = 'a', count = 2}, }	suite:assertDeepEquals(t[2], Reward.best(t))

t = { Reward.normalize {{kind = 'a'}, {kind = 'b'}}, Reward.normalize {kind = 'b'}, Reward.normalize {kind = 'a'}, }	suite:assertDeepEquals(t[1], Reward.best(t))

t = { Reward.normalize {kind = 'a'}, Reward.normalize {kind = 'b'}, Reward.normalize {{kind = 'a'}, {kind = 'b'}}, }	suite:assertDeepEquals(t[3], Reward.best(t)) end

return suite