From 4feb8c8da30d7453de45ed72b3395d2ed5e80e0c Mon Sep 17 00:00:00 2001 From: Zayer <86352017+ZayerRBLX@users.noreply.github.com> Date: Sat, 3 Feb 2024 14:10:51 +0100 Subject: [PATCH] Add test units for the isSimilar function (#285) (#311) --- test/Utility/isSimilar.spec.lua | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/Utility/isSimilar.spec.lua diff --git a/test/Utility/isSimilar.spec.lua b/test/Utility/isSimilar.spec.lua new file mode 100644 index 000000000..5d071140b --- /dev/null +++ b/test/Utility/isSimilar.spec.lua @@ -0,0 +1,35 @@ +local Package = game:GetService("ReplicatedStorage").Fusion +local isSimilar = require(Package.Utility.isSimilar) + +return function() + it("should return similar for identical values", function() + local value = 123 + + expect(isSimilar(value, value)).to.equal(true) + end) + + it("should return non-similar for different values", function() + local value1 = 123 + local value2 = 321 + + expect(isSimilar(value1, value2)).to.equal(false) + end) + + it("should return similar for any NaN values", function() + local nan1 = 0 / 0 + local nan2 = math.huge / math.huge + + expect(isSimilar(nan1, nan1)).to.equal(true) + expect(isSimilar(nan1, nan2)).to.equal(true) + end) + + it("should return non-similar for any tables", function() + local initialTable = { foo = 123, bar = "hello" } + local similarTable = { foo = 123, bar = "hello" } + local differentTable = { foo = 321, bar = "world" } + + expect(isSimilar(initialTable, initialTable)).to.equal(false) + expect(isSimilar(initialTable, similarTable)).to.equal(false) + expect(isSimilar(initialTable, differentTable)).to.equal(false) + end) +end \ No newline at end of file