local o=require("\078\101\120\117\115\085\110\105\116\084\101\115\116\105\110\103")local T=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local m=require((T: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 w=m:GetResource("\083\116\097\116\101\046\080\108\097\121\101\114\068\097\116\097")local e=o.UnitTest:Extend()function e.Setup(o)o.MockPlayer=Instance.new("\070\111\108\100\101\114")o.Folder=Instance.new("\070\111\108\100\101\114")o.Folder.Name="\080\108\097\121\101\114\068\097\116\097"o.Folder.Parent=o.MockPlayer o.CuT=w.GetPlayerData(o.MockPlayer)end o:RegisterUnitTest((e.new("\084\101\115\116\073\110\105\116\105\097\108\105\122\101\070\114\111\109\083\101\114\105\097\108\105\122\101\100\068\097\116\097")):SetRun(function(o)o.CuT:InitializeFromSerializedData()o:AssertEquals(#o.Folder:GetChildren(),10,"\087\114\111\110\103 \097\109\111\117\110\116 \111\102 \118\097\108\117\101\115 \099\114\101\097\116\101\100\046")o:AssertEquals(o.CuT:GetValue("\068\105\115\099\111\118\101\114\101\100\077\097\112\067\101\108\108\115"),"\091\093","\068\101\102\097\117\108\116 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.Folder.DiscoveredMapCells.Value,"\091\093","\068\101\102\097\117\108\116 \118\097\108\117\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetValue("\067\117\114\114\101\110\099\121"),0,"\068\101\102\097\117\108\116 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.Folder.Currency.Value,0,"\068\101\102\097\117\108\116 \118\097\108\117\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o.CuT:InitializeFromSerializedData({Currency=10})o:AssertEquals(#o.Folder:GetChildren(),10,"\087\114\111\110\103 \097\109\111\117\110\116 \111\102 \118\097\108\117\101\115 \099\114\101\097\116\101\100\046")o:AssertEquals(o.CuT:GetValue("\068\105\115\099\111\118\101\114\101\100\077\097\112\067\101\108\108\115"),"\091\093","\068\101\102\097\117\108\116 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.Folder.DiscoveredMapCells.Value,"\091\093","\068\101\102\097\117\108\116 \118\097\108\117\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetValue("\067\117\114\114\101\110\099\121"),10,"\083\101\116 \118\097\108\117\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.Folder.Currency.Value,10,"\083\101\116 \118\097\108\117\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o.CuT:InitializeFromSerializedData({Currency=10;UnknownValue="\070\097\105\108"})o:AssertEquals(#o.Folder:GetChildren(),10,"\087\114\111\110\103 \097\109\111\117\110\116 \111\102 \118\097\108\117\101\115 \099\114\101\097\116\101\100\046")o:AssertEquals(o.CuT:GetValue("\068\105\115\099\111\118\101\114\101\100\077\097\112\067\101\108\108\115"),"\091\093","\068\101\102\097\117\108\116 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.Folder.DiscoveredMapCells.Value,"\091\093","\068\101\102\097\117\108\116 \118\097\108\117\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetValue("\067\117\114\114\101\110\099\121"),10,"\083\101\116 \118\097\108\117\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.Folder.Currency.Value,10,"\083\101\116 \118\097\108\117\101 \105\115 \105\110\099\111\114\114\101\099\116\046")end))o:RegisterUnitTest((e.new("\084\101\115\116\083\101\116\086\097\108\117\101\065\110\100\069\118\101\110\116\115")):SetRun(function(o)o.CuT:InitializeFromSerializedData({Currency=10})local T,m={},0 o.CuT.ValueChanged:Connect(function(o)table.insert(T,o)end);(o.CuT:GetValueChangedSignal("\067\117\114\114\101\110\099\121")):Connect(function()m=m+1 end)o.CuT:SetValue("\067\117\114\114\101\110\099\121",12)o:AssertEquals(o.CuT:GetValue("\067\117\114\114\101\110\099\121"),12,"\083\101\116 \118\097\108\117\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.Folder.Currency.Value,12,"\083\101\116 \118\097\108\117\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(T,{"\067\117\114\114\101\110\099\121"},"\067\097\108\108\101\100 \101\118\101\110\116\115 \119\097\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(m,1,"\084\111\116\097\108 \099\097\108\108\101\100 \101\118\101\110\116\115 \119\097\115 \105\110\099\111\114\114\101\099\116\046")o.CuT:SetValue("\067\117\114\114\101\110\099\121",15)o:AssertEquals(o.CuT:GetValue("\067\117\114\114\101\110\099\121"),15,"\083\101\116 \118\097\108\117\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.Folder.Currency.Value,15,"\083\101\116 \118\097\108\117\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(T,{"\067\117\114\114\101\110\099\121","\067\117\114\114\101\110\099\121"},"\067\097\108\108\101\100 \101\118\101\110\116\115 \119\097\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(m,2,"\084\111\116\097\108 \099\097\108\108\101\100 \101\118\101\110\116\115 \119\097\115 \105\110\099\111\114\114\101\099\116\046")o.CuT:SetValue("\067\117\114\114\101\110\099\121",15)o:AssertEquals(o.CuT:GetValue("\067\117\114\114\101\110\099\121"),15,"\083\101\116 \118\097\108\117\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.Folder.Currency.Value,15,"\083\101\116 \118\097\108\117\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(T,{"\067\117\114\114\101\110\099\121","\067\117\114\114\101\110\099\121"},"\067\097\108\108\101\100 \101\118\101\110\116\115 \119\097\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(m,2,"\084\111\116\097\108 \099\097\108\108\101\100 \101\118\101\110\116\115 \119\097\115 \105\110\099\111\114\114\101\099\116\046")o.CuT:SetValue("\068\105\115\099\111\118\101\114\101\100\077\097\112\067\101\108\108\115","\091\049\044\050\044\051\093")o:AssertEquals(o.CuT:GetValue("\068\105\115\099\111\118\101\114\101\100\077\097\112\067\101\108\108\115"),"\091\049\044\050\044\051\093","\083\101\116 \118\097\108\117\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.Folder.DiscoveredMapCells.Value,"\091\049\044\050\044\051\093","\083\101\116 \118\097\108\117\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(T,{"\067\117\114\114\101\110\099\121";"\067\117\114\114\101\110\099\121";"\068\105\115\099\111\118\101\114\101\100\077\097\112\067\101\108\108\115"},"\067\097\108\108\101\100 \101\118\101\110\116\115 \119\097\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(m,2,"\084\111\116\097\108 \099\097\108\108\101\100 \101\118\101\110\116\115 \119\097\115 \105\110\099\111\114\114\101\099\116\046")end))return true
--[[
TheNexusAvenger

Tests the PlayerData class.
--]]

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

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



--[[
Setups up the test.
--]]
local PlayerDataTest = NexusUnitTesting.UnitTest:Extend()
function PlayerDataTest:Setup()
    --Create the component under testing.
    self.MockPlayer = Instance.new("Folder")
    self.Folder = Instance.new("Folder")
    self.Folder.Name = "PlayerData"
    self.Folder.Parent = self.MockPlayer
    self.CuT = PlayerData.GetPlayerData(self.MockPlayer)
end

--[[
Tests initializing from data.
--]]
NexusUnitTesting:RegisterUnitTest(PlayerDataTest.new("TestInitializeFromSerializedData"):SetRun(function(self)
    --Test loading with no data.
    self.CuT:InitializeFromSerializedData()
    self:AssertEquals(#self.Folder:GetChildren(),10,"Wrong amount of values created.")
    self:AssertEquals(self.CuT:GetValue("DiscoveredMapCells"),"[]","Default is incorrect.")
    self:AssertEquals(self.Folder.DiscoveredMapCells.Value,"[]","Default value is incorrect.")
    self:AssertEquals(self.CuT:GetValue("Currency"),0,"Default is incorrect.")
    self:AssertEquals(self.Folder.Currency.Value,0,"Default value is incorrect.")

    --Test loading with some data.
    self.CuT:InitializeFromSerializedData({Currency=10})
    self:AssertEquals(#self.Folder:GetChildren(),10,"Wrong amount of values created.")
    self:AssertEquals(self.CuT:GetValue("DiscoveredMapCells"),"[]","Default is incorrect.")
    self:AssertEquals(self.Folder.DiscoveredMapCells.Value,"[]","Default value is incorrect.")
    self:AssertEquals(self.CuT:GetValue("Currency"),10,"Set value is incorrect.")
    self:AssertEquals(self.Folder.Currency.Value,10,"Set value is incorrect.")

    --Test loading with extra data.
    self.CuT:InitializeFromSerializedData({Currency=10,UnknownValue="Fail"})
    self:AssertEquals(#self.Folder:GetChildren(),10,"Wrong amount of values created.")
    self:AssertEquals(self.CuT:GetValue("DiscoveredMapCells"),"[]","Default is incorrect.")
    self:AssertEquals(self.Folder.DiscoveredMapCells.Value,"[]","Default value is incorrect.")
    self:AssertEquals(self.CuT:GetValue("Currency"),10,"Set value is incorrect.")
    self:AssertEquals(self.Folder.Currency.Value,10,"Set value is incorrect.")
end))

--[[
Tests setting values and changed events.
--]]
NexusUnitTesting:RegisterUnitTest(PlayerDataTest.new("TestSetValueAndEvents"):SetRun(function(self)
    --Initialize the data and connect the events.
    self.CuT:InitializeFromSerializedData({Currency=10})
    local ChangedEventCalls,ValueChangedEventCalls = {},0
    self.CuT.ValueChanged:Connect(function(ValueName)
        table.insert(ChangedEventCalls,ValueName)
    end)
    self.CuT:GetValueChangedSignal("Currency"):Connect(function()
        ValueChangedEventCalls = ValueChangedEventCalls + 1
    end)

    --Set values and assert the changes were sent.
    self.CuT:SetValue("Currency",12)
    self:AssertEquals(self.CuT:GetValue("Currency"),12,"Set value is incorrect.")
    self:AssertEquals(self.Folder.Currency.Value,12,"Set value is incorrect.")
    self:AssertEquals(ChangedEventCalls,{"Currency"},"Called events was incorrect.")
    self:AssertEquals(ValueChangedEventCalls,1,"Total called events was incorrect.")
    self.CuT:SetValue("Currency",15)
    self:AssertEquals(self.CuT:GetValue("Currency"),15,"Set value is incorrect.")
    self:AssertEquals(self.Folder.Currency.Value,15,"Set value is incorrect.")
    self:AssertEquals(ChangedEventCalls,{"Currency","Currency"},"Called events was incorrect.")
    self:AssertEquals(ValueChangedEventCalls,2,"Total called events was incorrect.")
    self.CuT:SetValue("Currency",15)
    self:AssertEquals(self.CuT:GetValue("Currency"),15,"Set value is incorrect.")
    self:AssertEquals(self.Folder.Currency.Value,15,"Set value is incorrect.")
    self:AssertEquals(ChangedEventCalls,{"Currency","Currency"},"Called events was incorrect.")
    self:AssertEquals(ValueChangedEventCalls,2,"Total called events was incorrect.")
    self.CuT:SetValue("DiscoveredMapCells","[1,2,3]")
    self:AssertEquals(self.CuT:GetValue("DiscoveredMapCells"),"[1,2,3]","Set value is incorrect.")
    self:AssertEquals(self.Folder.DiscoveredMapCells.Value,"[1,2,3]","Set value is incorrect.")
    self:AssertEquals(ChangedEventCalls,{"Currency","Currency","DiscoveredMapCells"},"Called events was incorrect.")
    self:AssertEquals(ValueChangedEventCalls,2,"Total called events was incorrect.")
end))



return true