-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
5284 | ||
RobloxStudioBeta | ||
ADAM-PC | ||
8fadebc4-bf3a-4c4a-bb47-5300124d5ff3 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
local function ToKeyValuePairs1D<K, V>(Structure: {[K]: V}): {{Key: K, Value: V}} | ||
local Result = {} | ||
|
||
for Key, Value in Structure do | ||
table.insert(Result, { | ||
Key = Key; | ||
Value = Value; | ||
}) | ||
end | ||
|
||
return Result | ||
end | ||
|
||
return ToKeyValuePairs1D |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
return function() | ||
local ToKeyValuePairs1D = require(script.Parent.ToKeyValuePairs1D) | ||
|
||
describe("Map/ToKeyValuePairs1D", function() | ||
it("should return a blank array given an empty table", function() | ||
expect(#ToKeyValuePairs1D({})).to.equal(0) | ||
end) | ||
|
||
it("should return a single key-value pair for a single item table", function() | ||
local Result = ToKeyValuePairs1D({A = 1}) | ||
expect(#Result).to.equal(1) | ||
expect(Result[1].Key).to.equal("A") | ||
expect(Result[1].Value).to.equal(1) | ||
end) | ||
|
||
it("should return a key-value pair for each item in the table", function() | ||
local Result = ToKeyValuePairs1D({A = 1, B = 2, C = 3}) | ||
expect(#Result).to.equal(3) | ||
|
||
local function ArrayItemSatisfies(Condition) | ||
for _, Pair in Result do | ||
if Condition(Pair) then | ||
return true | ||
end | ||
end | ||
end | ||
|
||
expect(ArrayItemSatisfies(function(Pair) | ||
return Pair.Key == "A" and Pair.Value == 1 | ||
end)).to.equal(true) | ||
|
||
expect(ArrayItemSatisfies(function(Pair) | ||
return Pair.Key == "B" and Pair.Value == 2 | ||
end)).to.equal(true) | ||
|
||
expect(ArrayItemSatisfies(function(Pair) | ||
return Pair.Key == "C" and Pair.Value == 3 | ||
end)).to.equal(true) | ||
end) | ||
end) | ||
end |