This commit is contained in:
2025-07-15 01:28:53 -04:00
parent a1241905ea
commit cd27bdf2e0
6 changed files with 64 additions and 9 deletions

View File

@ -6,9 +6,7 @@ local numbers = Array.new()
for i = 1, 100 do
numbers:push(i)
end
print(numbers:debug_display(), "\nlength=", numbers:len())
local start = os.clock()
print(numbers:tostring(), "\nlength=", numbers:len())
numbers:map(function(n: number)
return tostring(n)
@ -16,6 +14,4 @@ end):foreach(function(e) print("(:map)squared=", e) end)
numbers:filter(function(n: number)
return bit32.band(n, 1) ~= 0
end):foreach(function(e) print("(:filter)odd=", e) end)
print(os.clock()-start)
end):foreach(function(e) print("(:filter)odd=", e) end)

13
tests/luau/reduce.luau Normal file
View File

@ -0,0 +1,13 @@
--!strict
local Array = require("../../luau/src")
local numbers = Array.new({1, 2, 3, 4})
print(numbers:tostring(), "\nlength=", numbers:len())
local sum = numbers:reduce(function(accumulator: number, currentValue: number)
return accumulator - currentValue
end)
print("sum=", sum)

13
tests/luau/reverse.luau Normal file
View File

@ -0,0 +1,13 @@
--!strict
local Array = require("../../luau/src")
local numbers = Array.new()
for i = 1, 100 do
numbers:push(i)
end
print(numbers:tostring(), "\nlength=", numbers:len())
numbers:reverse()
print(numbers:tostring())

18
tests/luau/slice.luau Normal file
View File

@ -0,0 +1,18 @@
--!strict
local Array = require("../../luau/src")
local animals = Array.new({"ant", "bison", "camel", "duck", "elephant"})
print(animals:tostring(), "\nlength=", animals:len())
local slice = animals:slice(3)
local slice2 = animals:slice(2,4)
local slice3 = animals:slice(1,5)
print("(:slice 3)" .. slice:tostring())
print("(:slice 2,4)" .. slice2:tostring())
print("(:slice 1,5)" .. slice3:tostring())
animals:join({"hi", "shrek"})
print("(:join)" .. animals:tostring())

11
tests/luau/sort.luau Normal file
View File

@ -0,0 +1,11 @@
--!strict
local Array = require("../../luau/src")
local months = Array.new({"March", "Jan", "Feb", "Dec"})
print(months:tostring(), "\nlength=", months:len())
months:sort()
print(months:tostring())

View File

@ -1,11 +1,15 @@
#!/bin/bash
touch results.txt
echo "" > results.txt
test () {
echo "-- [Test: $1] --" > results.txt
echo -e "\n-- [Test: $1] --" >> results.txt
luau $2 >> results.txt
echo "-- [Test: $1] --" >> results.txt
}
test "map_filter" "./luau/map_filter.luau"
test "map_filter" "./luau/map_filter.luau"
test "reverse" "./luau/reverse.luau"
test "reduce" "./luau/reduce.luau"
test "slice" "./luau/slice.luau"
test "sort" "./luau/sort.luau"