local B=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local R=require(B.Packages.Dex.Observables.State)local j=require(B.Packages.Dex.Util.MapObservable)return function()it("\109\097\112\115 \097 \115\105\110\103\108\101 \100\101\112\101\110\100\101\110\099\121",function()local B=R.new(5)local n=(j(B))(function(B)return B*2 end);(expect(n:Current())).to.equal(10)B:Set(7);(expect(n:Current())).to.equal(14)end)it("\109\097\112\115 \109\117\108\116\105\112\108\101 \100\101\112\101\110\100\101\110\099\105\101\115",function()local B=R.new(2)local n=R.new(3)local D=(j(B,n))(function(B,R)return B+R end);(expect(D:Current())).to.equal(5)B:Set(5);(expect(D:Current())).to.equal(8)n:Set(8);(expect(D:Current())).to.equal(13)end)it("\108\105\115\116\101\110\115 \116\111 \117\112\100\097\116\101\115 \102\114\111\109 \109\117\108\116\105\112\108\101 \100\101\112\101\110\100\101\110\099\105\101\115",function()local B=R.new(2)local n=R.new(3)local D=(j(B,n))(function(B,R)return B+R end)local C=0 D:Subscribe(function()C+=1 end);(expect(C)).to.equal(0);(expect(D:Current())).to.equal(5)B:Set(5);(expect(C)).to.equal(1);(expect(D:Current())).to.equal(8)B:Set(5);(expect(C)).to.equal(1);(expect(D:Current())).to.equal(8)n:Set(8);(expect(C)).to.equal(2);(expect(D:Current())).to.equal(13)n:Set(8);(expect(C)).to.equal(2);(expect(D:Current())).to.equal(13)end)end
--!strict
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local State = require(ReplicatedStorage.Packages.Dex.Observables.State)
local MapObservable = require(ReplicatedStorage.Packages.Dex.Util.MapObservable)

return function()
    it("maps a single dependency", function()
        local source = State.new(5)
		local mapped = MapObservable(source)(function(value)
			return value * 2
		end)
        
        expect(mapped:Current()).to.equal(10)
        
        source:Set(7)
        expect(mapped:Current()).to.equal(14)
    end)
    
    it("maps multiple dependencies", function()
        local dep1 = State.new(2)
        local dep2 = State.new(3)
        local mapped = MapObservable(dep1, dep2)(function(value1, value2)
            return value1 + value2
        end)
        
        expect(mapped:Current()).to.equal(5)
        
        dep1:Set(5)
        expect(mapped:Current()).to.equal(8)
        
        dep2:Set(8)
        expect(mapped:Current()).to.equal(13)
    end)

    it("listens to updates from multiple dependencies", function()
        local dep1 = State.new(2)
        local dep2 = State.new(3)
        local mapped = MapObservable(dep1, dep2)(function(value1, value2)
            return value1 + value2
        end)

        local updateCount = 0
        mapped:Subscribe(function()
            updateCount += 1
        end)

        expect(updateCount).to.equal(0)
        expect(mapped:Current()).to.equal(5)

        dep1:Set(5)
        expect(updateCount).to.equal(1)
        expect(mapped:Current()).to.equal(8)

        dep1:Set(5)
        expect(updateCount).to.equal(1)
        expect(mapped:Current()).to.equal(8)

        dep2:Set(8)
        expect(updateCount).to.equal(2)
        expect(mapped:Current()).to.equal(13)

        dep2:Set(8)
        expect(updateCount).to.equal(2)
        expect(mapped:Current()).to.equal(13)
    end)
end
