Skip to content

Commit

Permalink
With these commit we add resistors and wires and test their behavior …
Browse files Browse the repository at this point in the history
…using parametrized tests.
  • Loading branch information
jurra committed Jan 9, 2025
1 parent 2ad579d commit 87fc974
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/domain/entities/Resistor.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
// src/domain/entities/Resistor.js
export class Resistor {
constructor(id, position, resistance) {
this.id = id;
this.type = 'resistor'; // Used for rendering or logic
this.position = position; // Position value object
this.resistance = resistance; // Resistance value object
import { Element } from './Element.js';
import { Properties } from '../valueObjects/Properties.js';

/**
* Represents a Resistor in the circuit.
*/
export class Resistor extends Element {
/**
* Creates an instance of Resistor.
*
* @param {string} id - The unique identifier for the resistor.
* @param {Position[]} terminals - The two terminal positions for the resistor.
* @param {Label|null} label - The label of the resistor (optional).
* @param {Properties} properties - A container for the resistor's properties, including resistance.
*/
constructor(id, terminals, label = null, properties = new Properties({ resistance: "undefined" })) {
if (terminals.length !== 2) {
throw new Error("A Resistor must have exactly two terminals.");
}
super(id, terminals, label, properties);
this.type = 'resistor';
}
}
8 changes: 8 additions & 0 deletions src/domain/entities/Wire.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Element } from './Element.js';

export class Wire extends Element {
constructor(id, terminals, label = null, properties = new Properties()) {
super(id, terminals, label, properties);
this.type = 'wire';
}
}
8 changes: 8 additions & 0 deletions tests/domain/Element.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { expect } from 'chai';
import { Element } from '../../src/domain/entities/Element.js';
import { Resistor } from '../../src/domain/entities/Resistor.js';
import { Wire } from '../../src/domain/entities/Wire.js';
import { MockElement } from './MockElement.js'; // A mock element class for testing
import { Position } from '../../src/domain/valueObjects/Position.js';
import { Label } from '../../src/domain/valueObjects/Label.js';
Expand Down Expand Up @@ -80,4 +82,10 @@ describe('Element Class Tests', () => {

// Tests for MockElement
testElementSubclass('MockElement', MockElement, { mockProperty: 42 });

// Tests for Resistor
testElementSubclass('Resistor', Resistor, { resistance: 100 });

// Tests for Wire
testElementSubclass('Wire', Wire, {});
});

0 comments on commit 87fc974

Please sign in to comment.