|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { fx } from '../../src/core/system/System'; |
| 3 | + |
| 4 | +describe('fx (System)', () => { |
| 5 | + describe('Math Utilities', () => { |
| 6 | + it('distance should calculate Euclidean distance', () => { |
| 7 | + expect(fx.distance(0, 0, 3, 4)).toBe(5); |
| 8 | + expect(fx.distance(0, 0, 1, 1)).toBeCloseTo(1.41421356); |
| 9 | + }); |
| 10 | + |
| 11 | + it('lerp should interpolate between values', () => { |
| 12 | + expect(fx.lerp(0, 10, 0.5)).toBe(5); |
| 13 | + expect(fx.lerp(0, 10, 0)).toBe(0); |
| 14 | + expect(fx.lerp(0, 10, 1)).toBe(10); |
| 15 | + }); |
| 16 | + |
| 17 | + it('clamp should restrict values to range', () => { |
| 18 | + expect(fx.clamp(5, 0, 10)).toBe(5); |
| 19 | + expect(fx.clamp(-5, 0, 10)).toBe(0); |
| 20 | + expect(fx.clamp(15, 0, 10)).toBe(10); |
| 21 | + }); |
| 22 | + |
| 23 | + it('isNumber should identify numbers correctly', () => { |
| 24 | + expect(fx.isNumber(123)).toBe(true); |
| 25 | + expect(fx.isNumber('123')).toBe(true); |
| 26 | + expect(fx.isNumber('abc')).toBe(false); |
| 27 | + // Current implementation treats null as 0, hence isNumber(null) is true |
| 28 | + expect(fx.isNumber(null)).toBe(true); |
| 29 | + expect(fx.isNumber(undefined)).toBe(false); |
| 30 | + }); |
| 31 | + }); |
| 32 | + |
| 33 | + describe('Expression Evaluation', () => { |
| 34 | + it('evaluateExpression should handle basic arithmetic', () => { |
| 35 | + expect(fx.evaluateExpression('1 + 1')).toBe(2); |
| 36 | + expect(fx.evaluateExpression('10 * 2')).toBe(20); |
| 37 | + expect(fx.evaluateExpression('(2 + 3) * 4')).toBe(20); |
| 38 | + }); |
| 39 | + |
| 40 | + // Test a more complex case if possible, but keep it simple for now |
| 41 | + it('evaluateExpression should respect operator precedence', () => { |
| 42 | + expect(fx.evaluateExpression('2 + 3 * 4')).toBe(14); |
| 43 | + }); |
| 44 | + }); |
| 45 | +}); |
| 46 | + |
0 commit comments