Skip to content

Commit 7a2d64a

Browse files
committed
v0.3.7: add support for spherical tanks
1 parent 02bba49 commit 7a2d64a

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@adametherzlab/tank-level",
3-
"version": "0.3.6",
3+
"version": "0.3.7",
44
"description": "Tank level calculator — volume from height for cylindrical, rectangular, conical & spherical vessels with strapping tables, fill rate, alarms & inventory",
55
"type": "module",
66
"main": "src/index.ts",

tests/index.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,30 @@ describe("calculateVolume", () => {
7979
expect(result.volume).toBeCloseTo(expected, 2);
8080
});
8181

82+
it("should calculate volume for spherical vessel", () => {
83+
const config: VesselConfig = {
84+
type: "spherical",
85+
dimensions: { diameter: 2 },
86+
};
87+
88+
// Test empty
89+
let result = calculateVolume(config, 0);
90+
expect(result.volume).toBe(0);
91+
expect(result.percentage).toBe(0);
92+
93+
// Test full (diameter = 2, radius = 1)
94+
// Total volume = (4/3) * π * r³ = (4/3) * π
95+
result = calculateVolume(config, 2);
96+
expect(result.volume).toBeCloseTo((4 / 3) * Math.PI, 2);
97+
expect(result.percentage).toBe(100);
98+
99+
// Test half full (height = radius = 1)
100+
// Volume = (1/3) * π * h² * (3r - h) = (1/3) * π * 1 * (3 - 1) = (2/3) * π
101+
result = calculateVolume(config, 1);
102+
expect(result.volume).toBeCloseTo((2 / 3) * Math.PI, 2);
103+
expect(result.percentage).toBeCloseTo(50, 1);
104+
});
105+
82106
// Existing tests remain unchanged...
83107
});
84108

0 commit comments

Comments
 (0)