tests/ops: comments: specs only

This commit is contained in:
4DBug committed 2026-11-01 01:51:09 -05:00
1 parent 9d80ee11b9
commit 75ddfb4068
5 files changed
+7 -58

No files matched your search

+1 -10
View File
@@ -1,6 +1,4 @@
-- ops/AudioOps tests: toAudio from a Decoder, gain / gainDb / normalize, peak / RMS of known signals, remix matrices
-- (5.1 -> stereo -> mono, mono -> stereo / 5.1), resample through codecs/audio/Resample, trim, concat and mix with rate /
-- channel conversion, fades, bad arguments (Err.ARG, never a throw), and the F.ops facade.
-- ops/AudioOps tests on known signals.
local T = require("@tests/T")
local AudioOps = require("@rosetta/ops/AudioOps")
local Types = require("@rosetta/Types")
@@ -31,7 +29,6 @@ local sine = audio(8000, 2, 8000, function(f, c)
return (if c == 0 then 0.5 else 0.25) * math.sin(2 * math.pi * 440 * f / 8000)
end)
-- toAudio
do
local dec = Pcm.audioDecoder(sine)
local a = AudioOps.toAudio(dec) :: Types.Audio
@@ -41,7 +38,6 @@ do
t:check(e2 and e2.code == Err.LIMIT, "maxFrames -> LIMIT")
end
-- levels
do
local p, per = AudioOps.peak(sine)
t:check(near(p :: number, 0.5, 1e-3) and near((per :: any)[2], 0.25, 1e-3), "peak")
@@ -57,7 +53,6 @@ do
t:check(z and z.frames == 10, "normalize silence")
end
-- channels
do
-- 5.1 (WAVE order FL FR C LFE BL BR) with distinct constants
local five = audio(8000, 6, 4, function(_, c)
@@ -81,7 +76,6 @@ do
t:check(e and e.code == Err.ARG, "downmix to more channels: ARG")
end
-- time
do
local r = AudioOps.resample(sine, 16000) :: Types.Audio
t:check(r.sampleRate == 16000 and r.frames == 16000, "resample 8 -> 16 kHz")
@@ -108,7 +102,6 @@ do
t:check(at(fd, 0, 0) == 0 and near(at(fd, 2000, 0), at(sine, 2000, 0) * 0.5, 1e-6) and near(at(fd, 7999, 0), 0), "fades")
end
-- bad arguments: Err.ARG, never a throw
do
local junk: { any } = { nil, 5, "x", {}, { kind = "audio" }, Types.Image.new(2, 2) }
local calls = {
@@ -134,7 +127,6 @@ do
t:check(AudioOps.remix(sine, 0) == nil, "zero channels")
end
-- the F.ops facade
do
t:check(F.ops.audio == AudioOps, "F.ops.audio")
t:check(F.ops.image ~= nil and type(F.ops.image.resize) == "function", "F.ops.image")
@@ -147,5 +139,4 @@ do
t:check(F.ops.nothing == nil, "unknown ops: nil")
end
-- (no decoder here: the no-throw pass is the bad-arguments block above)
t:done()
+1 -15
View File
@@ -1,8 +1,4 @@
-- ops/ImageOps tests: against Pillow (tools/fixtures/imageops.py): grey conversion (exact), resize nearest / bilinear /
-- Lanczos up and down (max error), rotate with bilinear + expand (PSNR), alpha_composite (exact); property tests for
-- every pixel format (conversion round trips, flips, quarter turns, crop, premultiply, pixel access, fill), blit
-- clipping and blend modes, animation helpers (coalesce with each disposal, fromFrames, durations), and a pass of bad
-- arguments that must return nil, Err without throwing.
-- ops/ImageOps tests against Pillow (tools/fixtures/imageops.py) and property tests.
local T = require("@tests/T")
local Ops = require("@rosetta/ops/ImageOps")
local Types = require("@rosetta/Types")
@@ -17,7 +13,6 @@ local function image(w: number, h: number, fmt: string, px: string): any
return img
end
-- max abs difference and PSNR of two byte strings / buffers
local function diff(a: buffer, b: string): (number, number)
local n = #b
local mx, se = 0, 0
@@ -36,7 +31,6 @@ local rgb = image(Fx.rgb.w, Fx.rgb.h, "rgb8", Fx.rgb.px)
local rgba = image(Fx.rgba.w, Fx.rgba.h, "rgba8", Fx.rgba.px)
local rgba2 = image(Fx.rgba2.w, Fx.rgba2.h, "rgba8", Fx.rgba2.px)
-- Pillow references
do
local g = Ops.convert(rgb, "gray8") :: any
t:check(buffer.tostring(g.pixels) == Fx.gray, "rgb8 -> gray8 matches Pillow convert('L')")
@@ -67,7 +61,6 @@ do
t:check(mx == 0, "alpha_composite matches Pillow exactly (max error " .. mx .. ")")
end
-- conversions between every format
local FORMATS = { "rgba8", "rgba16", "rgbaf32", "rgb8", "gray8", "gray16", "graya8", "alpha8", "yuv420p" }
do
for _, f in FORMATS do
@@ -104,7 +97,6 @@ do
t:check(buffer.readu8(b.pixels, 0) == 255 and buffer.readu8(b.pixels, 1) == 0 and buffer.readu8(b.pixels, 2) == 128, "float -> 8 bit clamps and rounds")
end
-- geometry properties on every format
do
for _, f in FORMATS do
local img = Ops.convert(rgba, f) :: any
@@ -131,7 +123,6 @@ do
local rr = Ops.rotate(img, 33) :: any
t:check(rr and rr.format == f, f .. ": rotate 33")
end
-- crop content, nearest identity, ccw convention
local c = Ops.crop(rgba, 3, 4, 5, 6) :: any
t:check(buffer.readu32(c.pixels, 0) == buffer.readu32(rgba.pixels, (4 * rgba.width + 3) * 4), "crop origin")
t:check(buffer.tostring((Ops.resize(rgba, rgba.width, rgba.height, "lanczos") :: any).pixels) == buffer.tostring(rgba.pixels), "same-size resize is a copy")
@@ -139,7 +130,6 @@ do
t:eq(buffer.readu32(q.pixels, 0), buffer.readu32(rgba.pixels, (rgba.width - 1) * 4), "rotate90 is counter-clockwise")
end
-- pixels, fill, premultiply
do
for _, f in FORMATS do
local img = Ops.new(3, 2, f) :: any
@@ -173,7 +163,6 @@ do
t:note("premultiply round trip: max error %d for alpha >= 32", worst)
end
-- blit
do
local dst = Ops.new(10, 10, "rgba8") :: any
Ops.fill(dst, 10, 20, 30, 255)
@@ -191,7 +180,6 @@ do
Ops.blit(dst, src, 5, 5, { opacity = 0.5 })
local r = Ops.getPixel(dst, 5, 5)
t:check(math.abs(r - 133) <= 1, "opacity 0.5 over (10 -> " .. r .. ")")
-- rgb8 destination, gray source, float destination
local d3 = Ops.convert(dst, "rgb8") :: any
t:check(Ops.blit(d3, Ops.convert(src, "graya8") :: any, 1, 1) == d3, "blit onto rgb8")
local df = Ops.convert(dst, "rgbaf32") :: any
@@ -200,7 +188,6 @@ do
t:check(Ops.blit(dy, src, 3, 3) == dy, "blit onto yuv420p")
end
-- animation helpers
do
local W, H = 6, 4
local function solid(w: number, h: number, r: number, a: number): any
@@ -241,7 +228,6 @@ do
t:check(Ops.fromFrames({ fr[1], rgba }) == nil, "fromFrames refuses mixed sizes")
end
-- bad arguments: nil, Err, never a throw
do
local rand = T.rng(5)
local junk: { any } = { nil, 0, -1, 1.5, 2 ^ 40, "x", {}, true, 0 / 0, math.huge, -7 }
+1 -5
View File
@@ -1,6 +1,4 @@
-- ops/LayerOps + codecs/image/Blend tests: blend mode formulas on single pixels against hand-computed W3C values, opacity,
-- masks, clipping, isolated vs pass-through groups, hidden layers, frames, leaves, bad arguments. (Whole-document
-- flattening against psd-tools is in tests/layered/psd.luau.)
-- ops/LayerOps + codecs/image/Blend tests against hand-computed W3C values (flattening: tests/layered/psd.luau).
local T = require("@tests/T")
local LayerOps = require("@rosetta/ops/LayerOps")
local Blend = require("@rosetta/codecs/image/Blend")
@@ -72,7 +70,6 @@ do
local r2, _, _, a2 = get(LayerOps.flatten(doc({ top })))
t:check(r2 == 255 and math.abs(a2 - 128) <= 1, "over transparent: alpha scales")
end
-- hidden layers, masks, clipping
do
local top = L("top", px(255, 0, 0, 255))
top.visible = false
@@ -124,7 +121,6 @@ do
t:check(math.abs(get(LayerOps.flatten(doc({ bottom, g }))) - 100) <= 1, "pass-through: disabled mask ignored")
g.mask = nil
end
-- frames, leaves, flattenFrames
do
local d = doc({ L("a", px(1, 2, 3, 255)) })
d.frames = { { layers = d.layers, delay = 0.1 }, { layers = { L("b", px(9, 8, 7, 255)) }, delay = 0.2 } }
+2 -15
View File
@@ -1,8 +1,4 @@
-- ops/MeshOps tests: triangulate (strips, fans, convex / concave / degenerate n-gons), transform (normals by the inverse
-- transpose, mirrors flip the winding), computeNormals (smooth sphere normals = the radial direction, flat cube normals),
-- computeTangents (orthogonal, unit, handedness), weld / unweld, bounds, merge (instances baked, mixed attributes),
-- scale / setUnit / setUp, greedy voxel meshing (exposed face area, winding, the checkerboard worst case), errors.
-- Analytic references (closed forms); the format tests check merge / bounds against assimp and trimesh.
-- ops/MeshOps tests against analytic references (closed forms).
local T = require("@tests/T")
local MeshOps = require("@rosetta/ops/MeshOps")
local Types = require("@rosetta/Types")
@@ -52,7 +48,6 @@ local function area(prim: any): number
return total
end
-- a unit cube as 6 quads (polygons), 24 corners
local function cube(): Types.Primitive
local P = {}
local faces = {
@@ -76,7 +71,6 @@ local function cube(): Types.Primitive
return { attributes = { POSITION = f32(P, 3) }, indices = u32(ind), faces = u32(sizes), mode = "polygons" }
end
-- triangulate
do
local c = cube()
local tri = MeshOps.triangulate(c) :: any
@@ -95,7 +89,6 @@ do
end
end
t:check(outward, "triangulated winding keeps the faces outward")
-- strips and fans
local P = f32({ 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 2, 0, 1, 2, 0 }, 3)
local strip = MeshOps.triangulate({ attributes = { POSITION = P }, mode = "triangle_strip" }) :: any
t:check(table.concat(idx(strip.indices), ",") == "0,1,2,2,1,3,2,3,4,4,3,5", "strip unrolled with alternating winding")
@@ -130,7 +123,6 @@ do
t:check(MeshOps.triangulate(lines) == lines, "lines come back unchanged")
end
-- transform
do
local tri = MeshOps.triangulate(cube()) :: any
MeshOps.computeNormals(MeshOps.unweld(tri))
@@ -173,7 +165,6 @@ do
t:check(e and e.code == Err.ARG, "transform: a bad matrix")
end
-- normals, tangents on a UV sphere
do
local rings, segs = 16, 32
local P, UV, ind = {}, {}, {}
@@ -253,7 +244,6 @@ do
t:check(axis, "flat cube normals are axis-aligned")
end
-- weld
do
local soup = MeshOps.unweld(MeshOps.triangulate(cube()) :: any) :: any
t:eq(soup.attributes.POSITION.count, 36, "unwelded cube: 36 vertices")
@@ -271,7 +261,6 @@ do
t:eq(positionsOnly.attributes.POSITION.count, 8, "positionsOnly: 8")
end
-- merge, bounds
do
local s = S.new()
local tri = MeshOps.triangulate(cube()) :: any
@@ -301,11 +290,10 @@ do
t:check(e and e.code == Err.ARG, "merge junk")
end
-- units and up axis
do
local s = S.fromPrimitive(MeshOps.triangulate(cube()) :: any)
s.nodes[1].translation = { 1, 2, 3 }
s.meta.unit = 0.01 -- centimetres
s.meta.unit = 0.01
MeshOps.setUnit(s, 1)
local lo, hi = MeshOps.bounds(s)
t:check(lo and near(lo[1], 0.01) and near(hi[1], 0.02) and near(lo[3], 0.03), "cm -> m")
@@ -318,7 +306,6 @@ do
t:check(MeshOps.setUp(s, "x" :: any) == nil, "setUp: bad axis")
end
-- greedy voxels
do
local v = Types.Voxels.new(4, 4, 4)
for x = 0, 3 do
+2 -13
View File
@@ -1,6 +1,4 @@
-- ops/MusicOps tests (F.music.new / addPattern / setCell / getCell / addSample / addInstrument / note) and the
-- music-as-audio bridges of the api: F.save / F.convert of a Module or a Midi to an audio format (rendered, render
-- options through opts), F.audio.open / F.audio.load of music bytes. Everything is built here (no fixtures).
-- ops/MusicOps tests and the music-as-audio bridges of the api; everything is built here (no fixtures).
local T = require("@tests/T")
local F = require("@rosetta")
local Err = require("@rosetta/core/Err")
@@ -16,7 +14,6 @@ local function sine(rate: number, frames: number): any
return a
end
-- note names
do
t:eq(F.music.note("C-0"), 1, "C-0")
t:eq(F.music.note("C-4"), 49, "C-4")
@@ -32,7 +29,6 @@ do
end
end
-- a MOD built from scratch: saved, reloaded, rendered
local a = sine(8363, 8363)
local song = assert(F.music.new({ format = "mod", channels = 4, title = "demo", speed = 3 }))
do
@@ -47,7 +43,6 @@ do
t:check(F.music.setCell(song, p, 32, 2, { note = "E-4", instrument = s, effect = 0xC, param = 32 }), "setCell 2")
local c = assert(F.music.getCell(song, p, 32, 2))
t:check(c.note == 53 and c.instrument == 1 and c.effect == 0xC and c.param == 32 and c.volume == 0, "getCell")
-- bad arguments
local _, e1 = F.music.setCell(song, p, 64, 1, {})
t:check(e1 and e1.code == Err.ARG, "row out of range")
local _, e2 = F.music.setCell(song, p, 0, 5, {})
@@ -65,7 +60,7 @@ do
local _, e8 = F.music.addPattern({} :: any)
t:check(e8 and e8.code == Err.ARG, "not a module")
local mod = assert(F.save(song)) -- the source format
local mod = assert(F.save(song))
t:eq(F.detect(mod), "mod", "saved as MOD")
local back = assert(F.music.load(mod))
t:eq(back.title, "demo", "title round trip")
@@ -77,7 +72,6 @@ do
t:check(au.frames > 22050 and F.ops.audio.peak(au) > 0.05, "renders sound")
end
-- an XM with an instrument and a volume envelope
do
local xm = assert(F.music.new({ format = "xm", channels = 2 }))
local s = assert(F.music.addSample(xm, { audio = a, rate = 16726 })) -- an octave up: relativeNote 12
@@ -96,7 +90,6 @@ do
t:check(eenv and eenv.code == Err.ARG, "envelope ticks must increase")
end
-- music saved and converted as audio: rendered, with the render options from opts
do
local wav = assert(F.save(song, nil, { format = "wav", sampleRate = 22050 }))
local au = assert(F.audio.load(wav))
@@ -118,7 +111,6 @@ do
local mid = assert(F.save(m, nil, { format = "midi" }))
t:eq(F.detect(assert(F.convert(mid, "wav"))), "wav", "F.convert(midi, wav)")
-- F.audio.open / load of music bytes: the rendered Decoder
local d1 = assert(F.audio.open(mid, { tail = 0 }))
t:check(d1.channels == 2 and d1.sampleRate == 44100 and d1.frames == 22050, "F.audio.open(midi)")
local d2 = assert(F.audio.open(mod))
@@ -127,15 +119,12 @@ do
t:check(a2.kind == "audio" and a2.sampleRate == 8000, "F.audio.load(mod)")
local d3 = assert(F.audio.open(mod, { format = "mod" }))
t:check(d3.frames > 0, "F.audio.open with format = mod")
-- still an error for data no format reads
local _, e = F.audio.open(buffer.fromstring("not audio at all"))
t:check(e and e.code == Err.UNKNOWN_FORMAT, "unknown data")
-- and a soundfont is not audio
local _, e2 = F.audio.save(m, nil, { format = "png" })
t:check(e2 ~= nil, "music to a non-audio format fails")
end
-- no throws on random cell / sample arguments
do
local rng = T.rng(7)
local ok = true