local K=require((game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")):WaitForChild("\076\111\097\100\101\114"))local U=K("\112\108\097\121\101\114")local u=K("\068\097\116\097\083\121\110\099")local e=u.GetStore("\095\095\095\116\101\115\116\115\095\095\095",{Number=0,Boolean=true,Table={"\049";"\050";"\051"};Dictionary={a="\120";b="\121",c="\122"}})local M={}return{ParameterGenerator=function()local K repeat K=U.generate(1)until not table.find(M,K.UserId)table.insert(M,K.UserId)local u=e:GetFile(K.UserId)local X={number=math.random(1,100),boolean=math.random()>.5 and true or false,value=string.char(math.random(100,122))}return K,u,X end,Functions={add=function(K,U,u,e)local M=(u:IncrementData("\078\117\109\098\101\114",e.number)):GetData("\078\117\109\098\101\114")assert(typeof(M)=="\110\117\109\098\101\114","\070\097\105\108\101\100 \116\111 \097\100\100 \110\117\109\098\101\114\044 \103\111\116 \'"..(typeof(M).."\'"))end,subtract=function(K,U,u,e)local M=(u:IncrementData("\078\117\109\098\101\114",-e.number)):GetData("\078\117\109\098\101\114")assert(typeof(M)=="\110\117\109\098\101\114","\070\097\105\108\101\100 \116\111 \115\117\098\116\114\097\099\116 \110\117\109\098\101\114\044 \103\111\116 \'"..(typeof(M).."\'"))end,boolean=function(K,U,u,e)local M=(u:UpdateData("\066\111\111\108\101\097\110",e.boolean)):GetData("\066\111\111\108\101\097\110")assert(typeof(M)=="\098\111\111\108\101\097\110","\070\097\105\108\101\100 \116\111 \115\101\116 \098\111\111\108\101\097\110\044 \103\111\116 \'"..(typeof(M).."\'"))end;table=function(K,U,u,e)local M=u:GetData("\084\097\098\108\101")table.insert(M,e.value)local X=(u:UpdateData("\084\097\098\108\101",M)):GetData("\084\097\098\108\101")assert(typeof(X)=="\116\097\098\108\101","\070\097\105\108\101\100 \116\111 \115\101\116 \116\097\098\108\101\044 \103\111\116 \'"..(typeof(X).."\'"))end,dictionary=function(K,U,u,e)local M=u:GetData("\068\105\099\116\105\111\110\097\114\121")M[e.value]=e.number local X=(u:UpdateData("\068\105\099\116\105\111\110\097\114\121",M)):GetData("\068\105\099\116\105\111\110\097\114\121")assert(typeof(X)=="\116\097\098\108\101","\070\097\105\108\101\100 \116\111 \115\101\116 \100\105\099\116\105\111\110\097\114\121\044 \103\111\116 \'"..(typeof(X).."\'"))end,save=function(K,U,u,e)local M=u:SaveData()assert(M,"\070\097\105\108\101\100 \116\111 \115\097\118\101 \102\105\108\101")end;remove=function(K,U,u,e)local M=u:RemoveData()assert(getmetatable(M)==nil,"\070\097\105\108\101\100 \116\111 \100\101\115\116\114\111\121 \102\105\108\101")end,complete=function(K,U,u,e)local M=((((u:IncrementData("\078\117\109\098\101\114",e.number)):UpdateData("\066\111\111\108\101\097\110",e.boolean)):IncrementData("\078\117\109\098\101\114",-e.number)):UpdateData("\084\097\098\108\101",table.insert(u:GetData("\084\097\098\108\101"),e.value))):RemoveData()assert(typeof(M)=="\116\097\098\108\101"and getmetatable(M)==nil,"\070\097\105\108\101\100 \116\111 \114\117\110 \097 \099\111\109\112\108\101\116\101 \115\101\115\115\105\111\110")end}}
local require = require(game:GetService("ReplicatedStorage"):WaitForChild("Loader"))
local Player = require("player")
local DataSync = require("DataSync")

local Store = DataSync.GetStore("___tests___", {
	["Number"] = 0,
	["Boolean"] = true,
	["Table"] = { "1", "2", "3" },
	["Dictionary"] = {
		["a"] = "x",
		["b"] = "y",
		["c"] = "z",
	},
})

local Cache = {}

return {
	["ParameterGenerator"] = function()
		local plr
		repeat
			plr = Player.generate(1)
		until not table.find(Cache, plr.UserId)
		table.insert(Cache, plr.UserId)

		local file = Store:GetFile(plr.UserId)
		local data = {
			["number"] = math.random(1, 100),
			["boolean"] = math.random() > 0.5 and true or false,
			["value"] = string.char(math.random(100, 122)),
		}

		return plr, file, data
	end,

	["Functions"] = {
		["add"] = function(profiler, plr, file, data)
			local result = file:IncrementData("Number", data.number):GetData("Number")
			assert(typeof(result) == "number", "Failed to add number, got '" .. typeof(result) .. "'")
		end,

		["subtract"] = function(profiler, plr, file, data)
			local result = file:IncrementData("Number", -data.number):GetData("Number")
			assert(
				typeof(result) == "number",
				"Failed to subtract number, got '" .. typeof(result) .. "'"
			)
		end,

		["boolean"] = function(profiler, plr, file, data)
			local result = file:UpdateData("Boolean", data.boolean):GetData("Boolean")
			assert(typeof(result) == "boolean", "Failed to set boolean, got '" .. typeof(result) .. "'")
		end,

		["table"] = function(profiler, plr, file, data)
			local get = file:GetData("Table")
			table.insert(get, data.value)

			local result = file:UpdateData("Table", get):GetData("Table")
			assert(typeof(result) == "table", "Failed to set table, got '" .. typeof(result) .. "'")
		end,

		["dictionary"] = function(profiler, plr, file, data)
			local get = file:GetData("Dictionary")
			get[data.value] = data.number

			local result = file:UpdateData("Dictionary", get):GetData("Dictionary")
			assert(typeof(result) == "table", "Failed to set dictionary, got '" .. typeof(result) .. "'")
		end,

		["save"] = function(profiler, plr, file, data)
			local saved = file:SaveData()
			assert(saved, "Failed to save file")
		end,

		["remove"] = function(profiler, plr, file, data)
			local remove = file:RemoveData()
			assert(getmetatable(remove) == nil, "Failed to destroy file")
		end,

		["complete"] = function(profiler, plr, file, data)
			local result = file:IncrementData("Number", data.number):UpdateData("Boolean", data.boolean):IncrementData("Number", -data.number):UpdateData("Table", table.insert(file:GetData("Table"), data.value)):RemoveData()
			assert(
				typeof(result) == "table" and getmetatable(result) == nil,
				"Failed to run a complete session"
			)
		end,
	},
}
