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\097\116\104\070\105\110\100\046\071\114\097\112\104\083\111\108\118\101\114")local e=o.UnitTest:Extend()function e.Setup(o)o.CuT=w.new()o.CuT:AddNode("\065",0,0)o.CuT:AddNode("\066",2,0)o.CuT:AddNode("\067",0,3)o.CuT:AddNode("\068",4,4)o.CuT:AddNode("\069",1,-4)o.CuT:AddNode("\070",5,5)o.CuT:AddNode("\071",10,10)o.CuT:AddNode("\072",11,10)o.CuT:AddEdge("\065","\066")o.CuT:AddEdge("\065","\067")o.CuT:AddEdge("\065","\069")o.CuT:AddEdge("\066","\068")o.CuT:AddEdge("\067","\068")o.CuT:AddEdge("\068","\070")o.CuT:AddEdge("\069","\068")o.CuT:AddEdge("\069","\070")o.CuT:AddEdge("\071","\072")end function e.GetPathLength(o,...)local T=0 local m={...}for w=2,#m,1 do T=T+o.CuT:GetDistance(m[w-1],m[w])end return T end o:RegisterUnitTest((e.new("\084\101\115\116\071\101\116\083\104\111\114\116\101\115\116\068\105\115\116\097\110\099\101")):SetRun(function(o)o:AssertEquals(o.CuT:GetShortestDistance("\065","\065"),0,"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\065","\066"),o:GetPathLength("\065","\066"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\065","\067"),o:GetPathLength("\065","\067"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\065","\068"),o:GetPathLength("\065","\066","\068"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\065","\069"),o:GetPathLength("\065","\069"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\065","\070"),o:GetPathLength("\065","\066","\068","\070"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\065","\071"),nil,"\068\105\115\116\097\110\099\101 \101\120\105\115\116\115\046")o:AssertEquals(o.CuT:GetShortestDistance("\065","\072"),nil,"\068\105\115\116\097\110\099\101 \101\120\105\115\116\115\046")o:AssertEquals(o.CuT:GetShortestDistance("\066","\065"),o:GetPathLength("\065","\066"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\066","\066"),0,"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\066","\067"),o:GetPathLength("\066","\065","\067"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\066","\068"),o:GetPathLength("\066","\068"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\066","\069"),o:GetPathLength("\066","\065","\069"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\066","\070"),o:GetPathLength("\066","\068","\070"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\066","\071"),nil,"\068\105\115\116\097\110\099\101 \101\120\105\115\116\115\046")o:AssertEquals(o.CuT:GetShortestDistance("\066","\072"),nil,"\068\105\115\116\097\110\099\101 \101\120\105\115\116\115\046")o:AssertEquals(o.CuT:GetShortestDistance("\067","\065"),o:GetPathLength("\067","\065"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\067","\066"),o:GetPathLength("\066","\065","\067"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\067","\067"),0,"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\067","\068"),o:GetPathLength("\067","\068"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\067","\069"),o:GetPathLength("\067","\065","\069"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\067","\070"),o:GetPathLength("\067","\068","\070"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\067","\071"),nil,"\068\105\115\116\097\110\099\101 \101\120\105\115\116\115\046")o:AssertEquals(o.CuT:GetShortestDistance("\067","\072"),nil,"\068\105\115\116\097\110\099\101 \101\120\105\115\116\115\046")o:AssertEquals(o.CuT:GetShortestDistance("\068","\065"),o:GetPathLength("\068","\066","\065"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\068","\066"),o:GetPathLength("\068","\066"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\068","\067"),o:GetPathLength("\067","\068"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\068","\068"),0,"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\068","\069"),o:GetPathLength("\068","\069"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\068","\070"),o:GetPathLength("\068","\070"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\068","\071"),nil,"\068\105\115\116\097\110\099\101 \101\120\105\115\116\115\046")o:AssertEquals(o.CuT:GetShortestDistance("\068","\072"),nil,"\068\105\115\116\097\110\099\101 \101\120\105\115\116\115\046")o:AssertEquals(o.CuT:GetShortestDistance("\069","\065"),o:GetPathLength("\069","\065"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\069","\066"),o:GetPathLength("\069","\065","\066"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\069","\067"),o:GetPathLength("\069","\065","\067"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\069","\068"),o:GetPathLength("\069","\068"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\069","\069"),0,"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\069","\070"),o:GetPathLength("\069","\070"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\069","\071"),nil,"\068\105\115\116\097\110\099\101 \101\120\105\115\116\115\046")o:AssertEquals(o.CuT:GetShortestDistance("\069","\072"),nil,"\068\105\115\116\097\110\099\101 \101\120\105\115\116\115\046")o:AssertEquals(o.CuT:GetShortestDistance("\070","\065"),o:GetPathLength("\070","\068","\066","\065"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\070","\066"),o:GetPathLength("\070","\068","\066"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\070","\067"),o:GetPathLength("\070","\068","\067"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\070","\068"),o:GetPathLength("\070","\068"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\070","\069"),o:GetPathLength("\070","\069"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\070","\070"),0,"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\070","\071"),nil,"\068\105\115\116\097\110\099\101 \101\120\105\115\116\115\046")o:AssertEquals(o.CuT:GetShortestDistance("\070","\072"),nil,"\068\105\115\116\097\110\099\101 \101\120\105\115\116\115\046")o:AssertEquals(o.CuT:GetShortestDistance("\071","\065"),nil,"\068\105\115\116\097\110\099\101 \101\120\105\115\116\115\046")o:AssertEquals(o.CuT:GetShortestDistance("\071","\066"),nil,"\068\105\115\116\097\110\099\101 \101\120\105\115\116\115\046")o:AssertEquals(o.CuT:GetShortestDistance("\071","\067"),nil,"\068\105\115\116\097\110\099\101 \101\120\105\115\116\115\046")o:AssertEquals(o.CuT:GetShortestDistance("\071","\068"),nil,"\068\105\115\116\097\110\099\101 \101\120\105\115\116\115\046")o:AssertEquals(o.CuT:GetShortestDistance("\071","\069"),nil,"\068\105\115\116\097\110\099\101 \101\120\105\115\116\115\046")o:AssertEquals(o.CuT:GetShortestDistance("\071","\070"),nil,"\068\105\115\116\097\110\099\101 \101\120\105\115\116\115\046")o:AssertEquals(o.CuT:GetShortestDistance("\071","\071"),0,"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\071","\072"),o:GetPathLength("\071","\072"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\072","\065"),nil,"\068\105\115\116\097\110\099\101 \101\120\105\115\116\115\046")o:AssertEquals(o.CuT:GetShortestDistance("\072","\066"),nil,"\068\105\115\116\097\110\099\101 \101\120\105\115\116\115\046")o:AssertEquals(o.CuT:GetShortestDistance("\072","\067"),nil,"\068\105\115\116\097\110\099\101 \101\120\105\115\116\115\046")o:AssertEquals(o.CuT:GetShortestDistance("\072","\068"),nil,"\068\105\115\116\097\110\099\101 \101\120\105\115\116\115\046")o:AssertEquals(o.CuT:GetShortestDistance("\072","\069"),nil,"\068\105\115\116\097\110\099\101 \101\120\105\115\116\115\046")o:AssertEquals(o.CuT:GetShortestDistance("\072","\070"),nil,"\068\105\115\116\097\110\099\101 \101\120\105\115\116\115\046")o:AssertEquals(o.CuT:GetShortestDistance("\072","\071"),o:GetPathLength("\072","\071"),"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")o:AssertEquals(o.CuT:GetShortestDistance("\072","\072"),0,"\068\105\115\116\097\110\099\101 \105\115 \105\110\099\111\114\114\101\099\116\046")end))return true
--[[
TheNexusAvenger

Tests the GraphSolver class.
--]]

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

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



--[[
Setups up the test.
--]]
local GraphSolverTest = NexusUnitTesting.UnitTest:Extend()
function GraphSolverTest:Setup()
    --Create the component under testing.
    self.CuT = GraphSolver.new()

    --Add the nodes.
    self.CuT:AddNode("A",0,0)
    self.CuT:AddNode("B",2,0)
    self.CuT:AddNode("C",0,3)
    self.CuT:AddNode("D",4,4)
    self.CuT:AddNode("E",1,-4)
    self.CuT:AddNode("F",5,5)
    self.CuT:AddNode("G",10,10)
    self.CuT:AddNode("H",11,10)

    --Add the edges.
    self.CuT:AddEdge("A","B")
    self.CuT:AddEdge("A","C")
    self.CuT:AddEdge("A","E")
    self.CuT:AddEdge("B","D")
    self.CuT:AddEdge("C","D")
    self.CuT:AddEdge("D","F")
    self.CuT:AddEdge("E","D")
    self.CuT:AddEdge("E","F")
    self.CuT:AddEdge("G","H")
end

--[[
Returns the distance for a path.
--]]
function GraphSolverTest:GetPathLength(...)
    local Length = 0
    local Nodes = {...}
    for i = 2,#Nodes do
        Length = Length + self.CuT:GetDistance(Nodes[i - 1],Nodes[i])
    end
    return Length
end

--[[
Tests getting the shortest distance.
--]]
NexusUnitTesting:RegisterUnitTest(GraphSolverTest.new("TestGetShortestDistance"):SetRun(function(self)
    self:AssertEquals(self.CuT:GetShortestDistance("A","A"),0,"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("A","B"),self:GetPathLength("A","B"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("A","C"),self:GetPathLength("A","C"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("A","D"),self:GetPathLength("A","B","D"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("A","E"),self:GetPathLength("A","E"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("A","F"),self:GetPathLength("A","B","D","F"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("A","G"),nil,"Distance exists.")
    self:AssertEquals(self.CuT:GetShortestDistance("A","H"),nil,"Distance exists.")
    
    self:AssertEquals(self.CuT:GetShortestDistance("B","A"),self:GetPathLength("A","B"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("B","B"),0,"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("B","C"),self:GetPathLength("B","A","C"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("B","D"),self:GetPathLength("B","D"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("B","E"),self:GetPathLength("B","A","E"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("B","F"),self:GetPathLength("B","D","F"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("B","G"),nil,"Distance exists.")
    self:AssertEquals(self.CuT:GetShortestDistance("B","H"),nil,"Distance exists.")
    
    self:AssertEquals(self.CuT:GetShortestDistance("C","A"),self:GetPathLength("C","A"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("C","B"),self:GetPathLength("B","A","C"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("C","C"),0,"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("C","D"),self:GetPathLength("C","D"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("C","E"),self:GetPathLength("C","A","E"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("C","F"),self:GetPathLength("C","D","F"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("C","G"),nil,"Distance exists.")
    self:AssertEquals(self.CuT:GetShortestDistance("C","H"),nil,"Distance exists.")
    
    self:AssertEquals(self.CuT:GetShortestDistance("D","A"),self:GetPathLength("D","B","A"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("D","B"),self:GetPathLength("D","B"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("D","C"),self:GetPathLength("C","D"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("D","D"),0,"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("D","E"),self:GetPathLength("D","E"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("D","F"),self:GetPathLength("D","F"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("D","G"),nil,"Distance exists.")
    self:AssertEquals(self.CuT:GetShortestDistance("D","H"),nil,"Distance exists.")
    
    self:AssertEquals(self.CuT:GetShortestDistance("E","A"),self:GetPathLength("E","A"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("E","B"),self:GetPathLength("E","A","B"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("E","C"),self:GetPathLength("E","A","C"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("E","D"),self:GetPathLength("E","D"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("E","E"),0,"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("E","F"),self:GetPathLength("E","F"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("E","G"),nil,"Distance exists.")
    self:AssertEquals(self.CuT:GetShortestDistance("E","H"),nil,"Distance exists.")
    
    self:AssertEquals(self.CuT:GetShortestDistance("F","A"),self:GetPathLength("F","D","B","A"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("F","B"),self:GetPathLength("F","D","B"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("F","C"),self:GetPathLength("F","D","C"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("F","D"),self:GetPathLength("F","D"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("F","E"),self:GetPathLength("F","E"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("F","F"),0,"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("F","G"),nil,"Distance exists.")
    self:AssertEquals(self.CuT:GetShortestDistance("F","H"),nil,"Distance exists.")

    self:AssertEquals(self.CuT:GetShortestDistance("G","A"),nil,"Distance exists.")
    self:AssertEquals(self.CuT:GetShortestDistance("G","B"),nil,"Distance exists.")
    self:AssertEquals(self.CuT:GetShortestDistance("G","C"),nil,"Distance exists.")
    self:AssertEquals(self.CuT:GetShortestDistance("G","D"),nil,"Distance exists.")
    self:AssertEquals(self.CuT:GetShortestDistance("G","E"),nil,"Distance exists.")
    self:AssertEquals(self.CuT:GetShortestDistance("G","F"),nil,"Distance exists.")
    self:AssertEquals(self.CuT:GetShortestDistance("G","G"),0,"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("G","H"),self:GetPathLength("G","H"),"Distance is incorrect.")

    self:AssertEquals(self.CuT:GetShortestDistance("H","A"),nil,"Distance exists.")
    self:AssertEquals(self.CuT:GetShortestDistance("H","B"),nil,"Distance exists.")
    self:AssertEquals(self.CuT:GetShortestDistance("H","C"),nil,"Distance exists.")
    self:AssertEquals(self.CuT:GetShortestDistance("H","D"),nil,"Distance exists.")
    self:AssertEquals(self.CuT:GetShortestDistance("H","E"),nil,"Distance exists.")
    self:AssertEquals(self.CuT:GetShortestDistance("H","F"),nil,"Distance exists.")
    self:AssertEquals(self.CuT:GetShortestDistance("H","G"),self:GetPathLength("H","G"),"Distance is incorrect.")
    self:AssertEquals(self.CuT:GetShortestDistance("H","H"),0,"Distance is incorrect.")
end))



return true