local o=50 local T=require("\078\101\120\117\115\085\110\105\116\084\101\115\116\105\110\103")local m=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local w=require((m:WaitForChild("\080\114\111\106\101\099\116")):WaitForChild("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101"))local e=w:GetResource("\083\116\097\116\101\046\076\101\118\101\108\115")local C=T.UnitTest:Extend()function C.Setup(o)local T=Instance.new("\070\111\108\100\101\114")local m=Instance.new("\070\111\108\100\101\114")m.Name="\080\108\097\121\101\114\068\097\116\097"m.Parent=T local w=Instance.new("\073\110\116\086\097\108\117\101")w.Name="\088\080"w.Value=0 w.Parent=m o.XPValue=w o.CuT=e.new(T)end T:RegisterUnitTest((C.new("\084\101\115\116\083\101\116\116\105\110\103\088\080")):SetRun(function(T)T:AssertEquals(T.CuT.Level,1,"\076\101\118\101\108 \105\115 \105\110\118\097\108\105\100\046")T:AssertEquals(T.CuT.PreviousLevelExperience,0,"\067\117\114\114\101\110\116 \108\101\118\101\108 \088\080 \105\115 \105\110\118\097\108\105\100\046")T:AssertEquals(T.CuT.NextLevelExperience,o,"\078\101\120\116 \108\101\118\101\108 \088\080 \105\115 \105\110\118\097\108\105\100\046")T.XPValue.Value=.5*o T:AssertEquals(T.CuT.Level,1,"\076\101\118\101\108 \105\115 \105\110\118\097\108\105\100\046")T:AssertEquals(T.CuT.PreviousLevelExperience,0,"\067\117\114\114\101\110\116 \108\101\118\101\108 \088\080 \105\115 \105\110\118\097\108\105\100\046")T:AssertEquals(T.CuT.NextLevelExperience,1*o,"\078\101\120\116 \108\101\118\101\108 \088\080 \105\115 \105\110\118\097\108\105\100\046")T.XPValue.Value=1*o T:AssertEquals(T.CuT.Level,2,"\076\101\118\101\108 \105\115 \105\110\118\097\108\105\100\046")T:AssertEquals(T.CuT.PreviousLevelExperience,1*o,"\067\117\114\114\101\110\116 \108\101\118\101\108 \088\080 \105\115 \105\110\118\097\108\105\100\046")T:AssertEquals(T.CuT.NextLevelExperience,3*o,"\078\101\120\116 \108\101\118\101\108 \088\080 \105\115 \105\110\118\097\108\105\100\046")T.XPValue.Value=2*o T:AssertEquals(T.CuT.Level,2,"\076\101\118\101\108 \105\115 \105\110\118\097\108\105\100\046")T:AssertEquals(T.CuT.PreviousLevelExperience,1*o,"\067\117\114\114\101\110\116 \108\101\118\101\108 \088\080 \105\115 \105\110\118\097\108\105\100\046")T:AssertEquals(T.CuT.NextLevelExperience,3*o,"\078\101\120\116 \108\101\118\101\108 \088\080 \105\115 \105\110\118\097\108\105\100\046")T.XPValue.Value=3*o T:AssertEquals(T.CuT.Level,3,"\076\101\118\101\108 \105\115 \105\110\118\097\108\105\100\046")T:AssertEquals(T.CuT.PreviousLevelExperience,3*o,"\067\117\114\114\101\110\116 \108\101\118\101\108 \088\080 \105\115 \105\110\118\097\108\105\100\046")T:AssertEquals(T.CuT.NextLevelExperience,6*o,"\078\101\120\116 \108\101\118\101\108 \088\080 \105\115 \105\110\118\097\108\105\100\046")T.XPValue.Value=6*o T:AssertEquals(T.CuT.Level,4,"\076\101\118\101\108 \105\115 \105\110\118\097\108\105\100\046")T:AssertEquals(T.CuT.PreviousLevelExperience,6*o,"\067\117\114\114\101\110\116 \108\101\118\101\108 \088\080 \105\115 \105\110\118\097\108\105\100\046")T:AssertEquals(T.CuT.NextLevelExperience,10*o,"\078\101\120\116 \108\101\118\101\108 \088\080 \105\115 \105\110\118\097\108\105\100\046")T.XPValue.Value=10*o T:AssertEquals(T.CuT.Level,5,"\076\101\118\101\108 \105\115 \105\110\118\097\108\105\100\046")T:AssertEquals(T.CuT.PreviousLevelExperience,10*o,"\067\117\114\114\101\110\116 \108\101\118\101\108 \088\080 \105\115 \105\110\118\097\108\105\100\046")T:AssertEquals(T.CuT.NextLevelExperience,15*o,"\078\101\120\116 \108\101\118\101\108 \088\080 \105\115 \105\110\118\097\108\105\100\046")end))return true
--[[
TheNexusAvenger

Tests the Levels class.
--]]

local XP_MULTIPLIER = 50



local NexusUnitTesting = require("NexusUnitTesting")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ReplicatedStorageProject = require(ReplicatedStorage:WaitForChild("Project"):WaitForChild("ReplicatedStorage"))
local Levels = ReplicatedStorageProject:GetResource("State.Levels")



--[[
Setups up the test.
--]]
local InventoryTest = NexusUnitTesting.UnitTest:Extend()
function InventoryTest:Setup()
    --Create the mock player.
    local MockPlayer = Instance.new("Folder")
    local PlayerData = Instance.new("Folder")
    PlayerData.Name = "PlayerData"
    PlayerData.Parent = MockPlayer
    local XPValue = Instance.new("IntValue")
    XPValue.Name = "XP"
    XPValue.Value = 0
    XPValue.Parent = PlayerData
    self.XPValue = XPValue

    --Create the components under testing.
    self.CuT = Levels.new(MockPlayer)
end

--[[
Tests setting the level.
--]]
NexusUnitTesting:RegisterUnitTest(InventoryTest.new("TestSettingXP"):SetRun(function(self)
    --Assert the intial level is valid.
    self:AssertEquals(self.CuT.Level,1,"Level is invalid.")
    self:AssertEquals(self.CuT.PreviousLevelExperience,0,"Current level XP is invalid.")
    self:AssertEquals(self.CuT.NextLevelExperience,XP_MULTIPLIER,"Next level XP is invalid.")

    --Asset high levels are valid.
    self.XPValue.Value = 0.5 * XP_MULTIPLIER
    self:AssertEquals(self.CuT.Level,1,"Level is invalid.")
    self:AssertEquals(self.CuT.PreviousLevelExperience,0,"Current level XP is invalid.")
    self:AssertEquals(self.CuT.NextLevelExperience,1 * XP_MULTIPLIER,"Next level XP is invalid.")
    self.XPValue.Value = 1 * XP_MULTIPLIER
    self:AssertEquals(self.CuT.Level,2,"Level is invalid.")
    self:AssertEquals(self.CuT.PreviousLevelExperience,1 * XP_MULTIPLIER,"Current level XP is invalid.")
    self:AssertEquals(self.CuT.NextLevelExperience,3 * XP_MULTIPLIER,"Next level XP is invalid.")
    self.XPValue.Value = 2 * XP_MULTIPLIER
    self:AssertEquals(self.CuT.Level,2,"Level is invalid.")
    self:AssertEquals(self.CuT.PreviousLevelExperience,1 * XP_MULTIPLIER,"Current level XP is invalid.")
    self:AssertEquals(self.CuT.NextLevelExperience,3 * XP_MULTIPLIER,"Next level XP is invalid.")
    self.XPValue.Value = 3 * XP_MULTIPLIER
    self:AssertEquals(self.CuT.Level,3,"Level is invalid.")
    self:AssertEquals(self.CuT.PreviousLevelExperience,3 * XP_MULTIPLIER,"Current level XP is invalid.")
    self:AssertEquals(self.CuT.NextLevelExperience,6 * XP_MULTIPLIER,"Next level XP is invalid.")
    self.XPValue.Value = 6 * XP_MULTIPLIER
    self:AssertEquals(self.CuT.Level,4,"Level is invalid.")
    self:AssertEquals(self.CuT.PreviousLevelExperience,6 * XP_MULTIPLIER,"Current level XP is invalid.")
    self:AssertEquals(self.CuT.NextLevelExperience,10 * XP_MULTIPLIER,"Next level XP is invalid.")
    self.XPValue.Value = 10 * XP_MULTIPLIER
    self:AssertEquals(self.CuT.Level,5,"Level is invalid.")
    self:AssertEquals(self.CuT.PreviousLevelExperience,10 * XP_MULTIPLIER,"Current level XP is invalid.")
    self:AssertEquals(self.CuT.NextLevelExperience,15 * XP_MULTIPLIER,"Next level XP is invalid.")
end))



return true