From c4c1c840f8761ea45a3d2dcc912a59d8ced78cb5 Mon Sep 17 00:00:00 2001 From: LalleSX Date: Sat, 24 Oct 2026 04:35:56 +0200 Subject: init --- src/physics/electricField.test.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/physics/electricField.test.ts (limited to 'src/physics/electricField.test.ts') diff --git a/src/physics/electricField.test.ts b/src/physics/electricField.test.ts new file mode 100644 index 0000000..2e01309 --- /dev/null +++ b/src/physics/electricField.test.ts @@ -0,0 +1,21 @@ +import { describe, expect, it } from 'vitest'; +import { electricField, COULOMB_CONSTANT } from './electricField'; + +describe('Coulomb electric field', () => { + it('points away from a positive charge with inverse-square magnitude', () => { + const field = electricField({ x: 2, y: 0, z: 0 }, [{ x: 0, y: 0, z: 0, coulombs: 1e-9 }]); + expect(field.x).toBeCloseTo(COULOMB_CONSTANT * 1e-9 / 4); + expect(field.y).toBe(0); + expect(field.z).toBe(0); + }); + it('superposes opposite charges in the same direction at the midpoint', () => { + const field = electricField({ x: 0, y: 0, z: 0 }, [ + { x: -1, y: 0, z: 0, coulombs: 1e-9 }, + { x: 1, y: 0, z: 0, coulombs: -1e-9 }, + ]); + expect(field.x).toBeCloseTo(2 * COULOMB_CONSTANT * 1e-9); + }); + it('omits singular samples within the visualization exclusion radius', () => { + expect(electricField({ x: 0, y: 0, z: 0 }, [{ x: 0, y: 0, z: 0, coulombs: 1e-9 }])).toEqual({ x: 0, y: 0, z: 0 }); + }); +}); -- cgit v1.2.3