mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
finished a bunch of modules
- finished audio module - finished data module - finished filesystem module - finished font module (note: glphy test fails, but seems to be a 12.0 issue) - finished image module - finished maths module - finished sound module - finished thread module - finished video module - fixed pcall error not showing in results for invalid test code
This commit is contained in:
+153
-3
@@ -1,6 +1,156 @@
|
||||
-- love.math
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
--------------------------------------------------------------------------------
|
||||
------------------------------------OBJECTS-------------------------------------
|
||||
--------------------------------------------------------------------------------
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
-- BezierCurve (love.math.newBezierCurve)
|
||||
love.test.math.BezierCurve = function(test)
|
||||
-- create obj
|
||||
local curve = love.math.newBezierCurve(1, 1, 2, 2, 3, 1)
|
||||
local px, py = curve:getControlPoint(2)
|
||||
test:assertObject(curve)
|
||||
-- check initial properties
|
||||
test:assertCoords({2, 2}, {px, py}, 'check point x/y')
|
||||
test:assertEquals(3, curve:getControlPointCount(), 'check 3 points')
|
||||
test:assertEquals(2, curve:getDegree(), 'check degree is points-1')
|
||||
-- check some values on the curve
|
||||
test:assertEquals(1, curve:evaluate(0), 'check curve evaluation 0')
|
||||
test:assertEquals(120, math.floor(curve:evaluate(0.1)*100), 'check curve evaluation 0.1')
|
||||
test:assertEquals(140, math.floor(curve:evaluate(0.2)*100), 'check curve evaluation 0.2')
|
||||
test:assertEquals(200, math.floor(curve:evaluate(0.5)*100), 'check curve evaluation 0.5')
|
||||
test:assertEquals(3, curve:evaluate(1), 'check curve evaluation 1')
|
||||
-- check derivative
|
||||
local deriv = curve:getDerivative()
|
||||
test:assertObject(deriv)
|
||||
test:assertEquals(2, deriv:getControlPointCount(), 'check deriv points')
|
||||
test:assertEquals(200, math.floor(deriv:evaluate(0.1)*100), 'check deriv evaluation 0.1')
|
||||
-- check segment
|
||||
local segment = curve:getSegment(0, 0.5)
|
||||
test:assertObject(segment)
|
||||
test:assertEquals(3, segment:getControlPointCount(), 'check segment points')
|
||||
test:assertEquals(109, math.floor(segment:evaluate(0.1)*100), 'check segment evaluation 0.1')
|
||||
-- mess with control points
|
||||
curve:removeControlPoint(2)
|
||||
curve:insertControlPoint(4, 1, -1)
|
||||
curve:insertControlPoint(5, 3, -1)
|
||||
curve:insertControlPoint(6, 2, -1)
|
||||
curve:setControlPoint(2, 3, 2)
|
||||
test:assertEquals(5, curve:getControlPointCount(), 'check 3 points still')
|
||||
local px1, py1 = curve:getControlPoint(1)
|
||||
local px2, py2 = curve:getControlPoint(3)
|
||||
local px3, py3 = curve:getControlPoint(5)
|
||||
test:assertCoords({1, 1}, {px1, py1}, 'check modified point 1')
|
||||
test:assertCoords({5, 3}, {px2, py2}, 'check modified point 1')
|
||||
test:assertCoords({3, 1}, {px3, py3}, 'check modified point 1')
|
||||
-- check render lists
|
||||
local coords1 = curve:render(5)
|
||||
local coords2 = curve:renderSegment(0, 0.1, 5)
|
||||
test:assertEquals(196, #coords1, 'check coords')
|
||||
test:assertEquals(20, #coords2, 'check segment coords')
|
||||
-- check translation values
|
||||
px, py = curve:getControlPoint(2)
|
||||
test:assertCoords({3, 2}, {px, py}, 'check pretransform x/y')
|
||||
curve:rotate(90 * (math.pi/180), 0, 0)
|
||||
px, py = curve:getControlPoint(2)
|
||||
test:assertCoords({-2, 3}, {px, py}, 'check rotated x/y')
|
||||
curve:scale(2, 0, 0)
|
||||
px, py = curve:getControlPoint(2)
|
||||
test:assertCoords({-4, 6}, {px, py}, 'check scaled x/y')
|
||||
curve:translate(5, -5)
|
||||
px, py = curve:getControlPoint(2)
|
||||
test:assertCoords({1, 1}, {px, py}, 'check translated x/y')
|
||||
end
|
||||
|
||||
|
||||
-- RandomGenerator (love.math.RandomGenerator)
|
||||
-- @NOTE as this checks random numbers the chances this fails is very unlikely, but not 0...
|
||||
-- if you've managed to proc it congrats! your prize is to rerun the testsuite again
|
||||
love.test.math.RandomGenerator = function(test)
|
||||
-- create object
|
||||
local rng1 = love.math.newRandomGenerator(3418323524, 20529293)
|
||||
test:assertObject(rng1)
|
||||
-- check set properties
|
||||
local low, high = rng1:getSeed()
|
||||
test:assertEquals(3418323524, low, 'check seed low')
|
||||
test:assertEquals(20529293, high, 'check seed high')
|
||||
-- check states
|
||||
local rng2 = love.math.newRandomGenerator(1448323524, 10329293)
|
||||
test:assertNotEquals(rng1:random(), rng2:random(), 'check not matching states')
|
||||
test:assertNotEquals(rng1:randomNormal(), rng2:randomNormal(), 'check not matching states')
|
||||
-- check setting state works
|
||||
rng2:setState(rng1:getState())
|
||||
test:assertEquals(rng1:random(), rng2:random(), 'check now matching')
|
||||
-- check overwriting seed works, should change output
|
||||
rng1:setSeed(os.time())
|
||||
test:assertNotEquals(rng1:random(), rng2:random(), 'check not matching states')
|
||||
test:assertNotEquals(rng1:randomNormal(), rng2:randomNormal(), 'check not matching states')
|
||||
end
|
||||
|
||||
|
||||
-- Transform (love.math.Transform)
|
||||
love.test.math.Transform = function(test)
|
||||
-- create obj
|
||||
local transform = love.math.newTransform(0, 0, 0, 1, 1, 0, 0, 0, 0)
|
||||
test:assertObject(transform)
|
||||
-- set some values and check the matrix and transformPoint values
|
||||
transform:translate(10, 8)
|
||||
transform:scale(2, 3)
|
||||
transform:rotate(90*(math.pi/180))
|
||||
transform:shear(1, 2)
|
||||
local px, py = transform:transformPoint(1, 1)
|
||||
test:assertCoords({4, 14}, {px, py}, 'check transformation methods')
|
||||
transform:reset()
|
||||
px, py = transform:transformPoint(1, 1)
|
||||
test:assertCoords({1, 1}, {px, py}, 'check reset')
|
||||
-- apply a transform to another transform
|
||||
local transform2 = love.math.newTransform()
|
||||
transform2:translate(5, 3)
|
||||
transform:apply(transform2)
|
||||
px, py = transform:transformPoint(1, 1)
|
||||
test:assertCoords({6, 4}, {px, py}, 'check apply other transform')
|
||||
-- check cloning a transform
|
||||
local transform3 = transform:clone()
|
||||
px, py = transform3:transformPoint(1, 1)
|
||||
test:assertCoords({6, 4}, {px, py}, 'check clone transform')
|
||||
-- check inverse and inverseTransform
|
||||
transform:reset()
|
||||
transform:translate(-14, 6)
|
||||
local ipx, ipy = transform:inverseTransformPoint(0, 0)
|
||||
transform:inverse()
|
||||
px, py = transform:transformPoint(0, 0)
|
||||
test:assertCoords({-px, -py}, {ipx, ipy}, 'check inverse points transform')
|
||||
-- check matrix manipulation
|
||||
transform:setTransformation(0, 0, 0, 1, 1, 0, 0, 0, 0)
|
||||
transform:translate(4, 4)
|
||||
local m1, m2, m3, m4, m5, m6, m7, m8,
|
||||
m9, m10, m11, m12, m13, m14, m15, m16 = transform:getMatrix()
|
||||
test:assertEquals(4, m4, 'check translate matrix x')
|
||||
test:assertEquals(4, m8, 'check translate matrix y')
|
||||
transform:setMatrix(m1, m2, m3, 3, m5, m6, m7, 1, m9, m10, m11, m12, m13, m14, m15, m16)
|
||||
px, py = transform:transformPoint(1, 1)
|
||||
test:assertCoords({4, 2}, {px, py}, 'check set matrix')
|
||||
-- check affine vs non affine
|
||||
transform:reset()
|
||||
test:assertEquals(true, transform:isAffine2DTransform(), 'check affine 1')
|
||||
transform:translate(4, 3)
|
||||
test:assertEquals(true, transform:isAffine2DTransform(), 'check affine 2')
|
||||
transform:setMatrix(1, 3, 4, 5.5, 1, 4.5, 2, 1, 3.4, 5.1, 4.1, 13, 1, 1, 2, 3)
|
||||
test:assertEquals(false, transform:isAffine2DTransform(), 'check not affine')
|
||||
end
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
--------------------------------------------------------------------------------
|
||||
------------------------------------METHODS-------------------------------------
|
||||
--------------------------------------------------------------------------------
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
-- love.math.colorFromBytes
|
||||
love.test.math.colorFromBytes = function(test)
|
||||
-- check random value
|
||||
@@ -98,21 +248,21 @@ end
|
||||
|
||||
|
||||
-- love.math.newBezierCurve
|
||||
-- @NOTE this is just basic nil checking, full obj test are in objects.lua
|
||||
-- @NOTE this is just basic nil checking, objs have their own test method
|
||||
love.test.math.newBezierCurve = function(test)
|
||||
test:assertObject(love.math.newBezierCurve({0, 0, 0, 1, 1, 1, 2, 1}))
|
||||
end
|
||||
|
||||
|
||||
-- love.math.newRandomGenerator
|
||||
-- @NOTE this is just basic nil checking, full obj test are in objects.lua
|
||||
-- @NOTE this is just basic nil checking, objs have their own test method
|
||||
love.test.math.newRandomGenerator = function(test)
|
||||
test:assertObject(love.math.newRandomGenerator())
|
||||
end
|
||||
|
||||
|
||||
-- love.math.newTransform
|
||||
-- @NOTE this is just basic nil checking, full obj test are in objects.lua
|
||||
-- @NOTE this is just basic nil checking, objs have their own test method
|
||||
love.test.math.newTransform = function(test)
|
||||
test:assertObject(love.math.newTransform())
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user