You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactor tests to use updated geometry structure and enhance randomization tests
- Updated import paths in Polygon, Rectangle, and Vector tests to reflect new geometry structure.
- Added comprehensive tests for random number generation, including integers, decimals, booleans, and UUIDs.
- Removed outdated Maths utility tests as they are no longer relevant.
import{test,expect}from"vitest";import{Vector}from"../../../src/core/math/Vector";import{Circle}from"../../../src/core/math/Circle";import{Rectangle}from"../../../src/core/math/Rectangle";import{Polygon}from"../../../src/core/math/Polygon";test("Create circle from three points",()=>{conststart=newVector(0,6);constcenter=newVector(6,0);constend=newVector(2,2);constresult=Circle.ofPoints(start,center,end);constposition=result.getPosition();constradius=result.getRadius();expect(position.x).toBe(7);expect(position.y).toBe(7);expect(position.z).toBe(0);expect(radius).approximately(7.071,0.1);});test("Circle intersects with circle",()=>{constvalue=newCircle(6,6,6);constpositiveValue=newCircle(0,0,3);constnegativeValue=newCircle(100,100,6);letresult=value.intersects(positiveValue);expect(result).toBeTruthy();result=value.intersects(negativeValue);expect(result).toBeFalsy();});test("Circle intersects with rectangle",()=>{constvalue=newCircle(0,0,4);constpositiveValue=newRectangle(-2,-2,10,5);constnegativeValue=newRectangle(100,100,10,5);letresult=value.intersects(positiveValue);expect(result).toBeTruthy();result=value.intersects(negativeValue);expect(result).toBeFalsy();});test("Circle intersects with polygon",()=>{constvalue=newCircle(0,0,4);constpositiveValue=newPolygon([newVector(1,-2),newVector(1,2),newVector(0,8)]);constnegativeValue=newPolygon([newVector(5,5),newVector(10,10),newVector(5,15)]);letresult=value.intersects(positiveValue);expect(result).toBeTruthy();result=value.intersects(negativeValue);expect(result).toBeFalsy();});test("Circle intersects with null",()=>{constvalue=newCircle(0,0,4);consterrorValue=null;constresult=value.intersects(errorValue);expect(result).toBeFalsy();});test("Get border point of circle",()=>{constvalue=newCircle(6,6,6);constresult=value.getBorderPoint(90);expect(result.x).approximately(6,0.1);expect(result.y).toBe(0);expect(result.z).toBe(0);});test("Get area of circle",()=>{constvalue=newCircle(0,0,6);constresult=value.getArea();expect(result).approximately(113.0973,0.1);});test("Get perimeter of circle",()=>{constvalue=newCircle(0,0,6);constresult=value.getPerimeter();expect(result).approximately(37.6991,0.1);});test("Get diameter of circle",()=>{constvalue=newCircle(0,0,6);constresult=value.getDiameter();expect(result).toBe(12);});
import{test,expect}from"vitest";import{Line}from"../../../src/core/math/Line";import{Vector}from"../../../src/core/math/Vector";import{Circle}from"../../../src/core/math/Circle";import{Rectangle}from"../../../src/core/math/Rectangle";import{Polygon}from"../../../src/core/math/Polygon";test("Create line from two points",()=>{conststart=newVector(0,0);constend=newVector(6,0);constresult=Line.ofPoints(start,end);constlineStart=result.getStart();expect(lineStart.x).toBe(0);expect(lineStart.y).toBe(0);expect(lineStart.z).toBe(0);constlineEnd=result.getEnd();expect(lineEnd.x).toBe(6);expect(lineEnd.y).toBe(0);expect(lineEnd.z).toBe(0);});test("Line contains point",()=>{constvalue=newLine(0,0,6,0);constpositiveValue=newVector(3,0);constnegativeValue=newVector(9,0);letresult=value.contains(positiveValue);expect(result).toBeTruthy();result=value.contains(negativeValue);expect(result).toBeFalsy();});test("Line intersects with line",()=>{constvalue=newLine(0,0,6,0);constpositiveValue=newLine(3,3,3,-3);constnegativeValue=newLine(0,3,3,3);letresult=value.intersects(positiveValue);expect(result).toBeTruthy();result=value.intersects(negativeValue);expect(result).toBeFalsy();});test("Line intersects with circle",()=>{constvalue=newLine(0,0,6,0);constpositiveValue=newCircle(0,3,3);constnegativeValue=newCircle(5,5,2);letresult=value.intersects(positiveValue);expect(result).toBeTruthy();result=value.intersects(negativeValue);expect(result).toBeFalsy();});test("Line intersects with rectangle",()=>{constvalue=newLine(0,0,6,0);constpositiveValue=newRectangle(1,-2,3,4);constnegativeValue=newRectangle(100,100,1,1);letresult=value.intersects(positiveValue);expect(result).toBeTruthy();result=value.intersects(negativeValue);expect(result).toBeFalsy();});test("Line intersects with polygon",()=>{constvalue=newLine(0,0,6,0);constpositiveValue=newPolygon([newVector(1,-2),newVector(1,2),newVector(0,8)]);constnegativeValue=newPolygon([newVector(5,5),newVector(10,10),newVector(5,15)]);letresult=value.intersects(positiveValue);expect(result).toBeTruthy();result=value.intersects(negativeValue);expect(result).toBeFalsy();});test("Line intersects with null",()=>{constvalue=newLine(0,0,6,0);consterrorValue=null;constresult=value.intersects(errorValue);expect(result).toBeFalsy();});test("Reflect vector with line",()=>{constvalue=newLine(0,0,0,6);constother=newVector(-6,3);constresult=value.reflect(other);expect(result.x).toBe(6);expect(result.y).toBe(3);expect(result.z).toBe(0);});test("Get vertical bisector of line",()=>{constvalue=newLine(0,0,0,6);constresult=value.getVerticalBisector();expect(result.A).toBe(-0);expect(result.B).toBe(6);expect(result.C).toBe(18);});test("Two lines are parallel",()=>{constvalue=newLine(0,0,6,0);constpositiveValue=newLine(0,6,6,6);constnegativeValue=newLine(3,-3,3,3);letresult=value.isParallel(positiveValue);expect(result).toBeTruthy();result=value.isParallel(negativeValue);expect(result).toBeFalsy();});test("Get angle of line",()=>{constvalue=newLine(0,0,1,1);constresult=value.getAngle();expect(result).toBe(45);});test("Get slope of line",()=>{constvalue=newLine(0,0,1,1);constresult=value.getSlope();expect(result).toBe(1);});test("Get center of line",()=>{constvalue=newLine(0,0,6,0);constresult=value.getCenter();expect(result.x).toBe(3);expect(result.y).toBe(0);expect(result.z).toBe(0);});
0 commit comments