-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
With these commit we add resistors and wires and test their behavior …
…using parametrized tests.
- Loading branch information
Showing
3 changed files
with
37 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters