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=game:GetService("\072\116\116\112\083\101\114\118\105\099\101")local w=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 e=w:GetResource("\083\116\097\116\101\046\066\111\111\108\071\114\105\100")local C=o.UnitTest:Extend()function C.Setup(o)o.CuT=e.new(5,5)end o:RegisterUnitTest((C.new("\084\101\115\116\076\111\097\100\105\110\103\071\114\105\100")):SetRun(function(o)o.CuT:LoadFromString(m:JSONEncode({{true;5},{false;5},{true,3,2};{true;1,1,1;1,1},{false;2;1;2}}))o:AssertEquals(m:JSONEncode({{true,true,true,true;true};{false,false;false,false;false},{true,true,true;false;false};{true,false,true;false,true},{false;false,true,false;false}}),m:JSONEncode(o.CuT.Grid),"\071\114\105\100 \105\115 \105\110\099\111\114\114\101\099\116\046")end))o:RegisterUnitTest((C.new("\084\101\115\116\083\101\114\105\097\108\105\122\101")):SetRun(function(o)o.CuT:LoadFromString(m:JSONEncode({{true;5},{false;5},{true;3,2};{true,1;1;1,1,1};{false;2;1,2}}))o:AssertEquals(m:JSONEncode({{true;5};{false;5};{true,3;2};{true;1,1;1,1,1};{false;2,1,2}}),o.CuT:Serialize(),"\068\097\116\097 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetValue(-1,1),false,"\079\117\116 \111\102 \114\097\110\103\101 \118\097\108\117\101 \105\115 \105\110\118\097\108\105\100\046")o:AssertEquals(o.CuT:GetValue(1,-1),false,"\079\117\116 \111\102 \114\097\110\103\101 \118\097\108\117\101 \105\115 \105\110\118\097\108\105\100\046")o:AssertEquals(o.CuT:GetValue(1,6),false,"\079\117\116 \111\102 \114\097\110\103\101 \118\097\108\117\101 \105\115 \105\110\118\097\108\105\100\046")o:AssertEquals(o.CuT:GetValue(1,6),false,"\079\117\116 \111\102 \114\097\110\103\101 \118\097\108\117\101 \105\115 \105\110\118\097\108\105\100\046")o:AssertEquals(o.CuT:GetValue(1,1),true,"\086\097\108\117\101 \105\115 \105\110\118\097\108\105\100\046")o:AssertEquals(o.CuT:GetValue(2,3),false,"\086\097\108\117\101 \105\115 \105\110\118\097\108\105\100\046")o:AssertEquals(o.CuT:GetValue(3,2),true,"\086\097\108\117\101 \105\115 \105\110\118\097\108\105\100\046")o.CuT:SetValue(1,3,false)o.CuT:SetValue(5,3,false)o:AssertEquals(m:JSONEncode({{true;2;1,2};{false;5},{true,3;2},{true;1,1;1,1;1},{false;5}}),o.CuT:Serialize(),"\068\097\116\097 \105\115 \105\110\099\111\114\114\101\099\116\046")end))return true
--[[
TheNexusAvenger

Tests the BoolGrid class.
--]]

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

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



--[[
Setups up the test.
--]]
local BoolGridTest = NexusUnitTesting.UnitTest:Extend()
function BoolGridTest:Setup()
    --Create the component under testing.
    self.CuT = BoolGrid.new(5,5)
end

--[[
Tests loading a grid from a string.
--]]
NexusUnitTesting:RegisterUnitTest(BoolGridTest.new("TestLoadingGrid"):SetRun(function(self)
    --Load the grid data.
    self.CuT:LoadFromString(HttpService:JSONEncode({
        {true,5},
        {false,5},
        {true,3,2},
        {true,1,1,1,1,1},
        {false,2,1,2}
    }))

    --Assert the grid is connect.
    self:AssertEquals(HttpService:JSONEncode({{true,true,true,true,true},{false,false,false,false,false},{true,true,true,false,false},{true,false,true,false,true},{false,false,true,false,false}}),HttpService:JSONEncode(self.CuT.Grid),"Grid is incorrect.")
end))

--[[
Tests serializing the grid.
--]]
NexusUnitTesting:RegisterUnitTest(BoolGridTest.new("TestSerialize"):SetRun(function(self)
    --Load the grid data.
    self.CuT:LoadFromString(HttpService:JSONEncode({
        {true,5},
        {false,5},
        {true,3,2},
        {true,1,1,1,1,1},
        {false,2,1,2}
    }))

    --Assert the data is correct.
    self:AssertEquals(HttpService:JSONEncode({
        {true,5},
        {false,5},
        {true,3,2},
        {true,1,1,1,1,1},
        {false,2,1,2}
    }),self.CuT:Serialize(),"Data is incorrect.")

    --Assert multiple values are valid and set values.
    self:AssertEquals(self.CuT:GetValue(-1,1),false,"Out of range value is invalid.")
    self:AssertEquals(self.CuT:GetValue(1,-1),false,"Out of range value is invalid.")
    self:AssertEquals(self.CuT:GetValue(1,6),false,"Out of range value is invalid.")
    self:AssertEquals(self.CuT:GetValue(1,6),false,"Out of range value is invalid.")
    self:AssertEquals(self.CuT:GetValue(1,1),true,"Value is invalid.")
    self:AssertEquals(self.CuT:GetValue(2,3),false,"Value is invalid.")
    self:AssertEquals(self.CuT:GetValue(3,2),true,"Value is invalid.")
    self.CuT:SetValue(1,3,false)
    self.CuT:SetValue(5,3,false)

    --Assert the new data is correct.
    self:AssertEquals(HttpService:JSONEncode({
        {true,2,1,2},
        {false,5},
        {true,3,2},
        {true,1,1,1,1,1},
        {false,5}
    }),self.CuT:Serialize(),"Data is incorrect.")
end))



return true