local l=require((game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")).MockMemoryStore)return function()it("\083\104\111\117\108\100 \114\101\116\114\105\101\118\101 \116\104\101 \115\097\109\101 \109\097\112",function()local r=l:GetSortedMap("\084\101\115\116\083\111\114\116\101\100\077\097\112");(expect(r)).to.be.ok()local i=l:GetSortedMap("\084\101\115\116\083\111\114\116\101\100\077\097\112");(expect(i)).to.equal(r)end)it("\083\104\111\117\108\100 \099\111\114\114\101\099\116\108\121 \117\115\101 \071\101\116\065\115\121\110\099\047\083\101\116\065\115\121\110\099",function()local r=10 local i=l:GetSortedMap("\084\101\115\116\083\111\114\116\101\100\077\097\112");(expect(i:SetAsync("\084\101\115\116\083\101\116",r,30))).to.equal(false);(expect(i:GetAsync("\084\101\115\116\083\101\116"))).to.equal(r);(expect(i:SetAsync("\084\101\115\116\083\101\116",r+5,30))).to.equal(true)end)it("\083\104\111\117\108\100 \099\111\114\114\101\099\116\108\121 \117\115\101 \085\112\100\097\116\101\065\115\121\110\099",function()local r=32 local i=l:GetSortedMap("\084\101\115\116\083\111\114\116\101\100\077\097\112")local y=i:UpdateAsync("\084\101\115\116\085\112\100\097\116\101\075\101\121",function(l)(expect(l)).to.be.equal(nil)return r end,20);(expect(y)).to.be.equal(r)local P=i:UpdateAsync("\084\101\115\116\085\112\100\097\116\101\075\101\121",function(l)(expect(l)).to.equal(r)return nil end,20);(expect(P)).to.equal(nil)end)it("\083\104\111\117\108\100 \099\111\114\114\101\099\116\108\121 \117\115\101 \082\101\109\111\118\101\065\115\121\110\099",function()local r=32 local i=l:GetSortedMap("\084\101\115\116\083\111\114\116\101\100\077\097\112");(expect(i:SetAsync("\082\101\109\111\118\101\077\101",r,30))).to.equal(false)i:RemoveAsync("\082\101\109\111\118\101\077\101");(expect(i:GetAsync("\082\101\109\111\118\101\077\101"))).to.equal(nil)end)end
local MockMemoryStoreService = require(game:GetService("ReplicatedStorage").MockMemoryStore)


return function ()
    it("Should retrieve the same map", function()
        local TestSortedMap = MockMemoryStoreService:GetSortedMap("TestSortedMap")
        expect(TestSortedMap).to.be.ok()

        local TestSortedMap2 = MockMemoryStoreService:GetSortedMap("TestSortedMap")
        expect(TestSortedMap2).to.equal(TestSortedMap) -- Should be same reference
    end)

    it("Should correctly use GetAsync/SetAsync", function()
        local TEST_VALUE = 10

        local TestSortedMap = MockMemoryStoreService:GetSortedMap("TestSortedMap")
        expect(TestSortedMap:SetAsync("TestSet", TEST_VALUE, 30)).to.equal(false)  -- false because new value, not update.

        expect(TestSortedMap:GetAsync("TestSet")).to.equal(TEST_VALUE)

        expect(TestSortedMap:SetAsync("TestSet", TEST_VALUE + 5, 30)).to.equal(true) -- true, because updating existing value
    end)

    it("Should correctly use UpdateAsync", function()
        local TEST_VALUE = 32

        local TestSortedMap = MockMemoryStoreService:GetSortedMap("TestSortedMap")

        -- This should return a value, since we've returned a value
        local value = TestSortedMap:UpdateAsync("TestUpdateKey", function(value)
            expect(value).to.be.equal(nil) -- value shouldn't be set since it's y'know, not set yet.
            return TEST_VALUE
        end, 20)

        -- Should have returned TEST_VALUE
        expect(value).to.be.equal(TEST_VALUE)

        local nilValue = TestSortedMap:UpdateAsync("TestUpdateKey", function(value)
            expect(value).to.equal(TEST_VALUE)
            return nil
        end, 20)

        -- Should be nil since we didn't transform
        expect(nilValue).to.equal(nil)
    end)

    it("Should correctly use RemoveAsync", function()
        local TEST_VALUE = 32
        local TestSortedMap = MockMemoryStoreService:GetSortedMap("TestSortedMap")

        expect(TestSortedMap:SetAsync("RemoveMe", TEST_VALUE, 30)).to.equal(false) -- new value, again

        TestSortedMap:RemoveAsync("RemoveMe")
        expect(TestSortedMap:GetAsync("RemoveMe")).to.equal(nil)
    end)
end