Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bumps muriatic amounts, adds tests #6

Merged
merged 2 commits into from Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 9 additions & 11 deletions formulas/treatments/m_acid.ts
Expand Up @@ -12,34 +12,32 @@ export const m_acid: Treatment = {
// Muriatic Acid helps to lower the pH. I personally don't like
// how the acid makes the water slimy & unswimmable for a few hours...
// but meh.

// This is not very precise, feel free to remix. It's another non-linear effect,
// where the multiplier is different depending on the measure.
let multiplier = 0;
const r = extra.readings;

if (r.ph > 8.2) {
multiplier = -.0027;
multiplier = -.00405;
}
else if (r.ph > 8.0) {
multiplier = -.0028;
multiplier = -.0042;
}
else if (r.ph > 7.8) {
multiplier = -.0029;
multiplier = -.00435;
}
else if (r.ph > 7.6) {
multiplier = -.0030;
multiplier = -.0045;
}


const maxAmount = .0032 * pool.gallons;

const maxAmount = 0.0075 * pool.gallons;
const calculatedAmount = pool.gallons * deltas.ph * multiplier;
// Cap the total amount of acid, just in-case someone enters a pH of 100 somehow:
const amount = Math.min(maxAmount, calculatedAmount);

const effectOnPH = amount / (pool.gallons * multiplier);

const effectOnPH = amount / (pool.gallons * multiplier);

return {
amount,
effects: {
Expand Down
2 changes: 1 addition & 1 deletion tests/formulas/bromine.test.ts
Expand Up @@ -64,7 +64,7 @@ describe('Bromine Formula', () => {

// Assert
expect(Object.keys(res).length).toBe(1);
expect(res.m_acid).toBeCloseTo(17.4);
expect(res.m_acid).toBeCloseTo(26.1);
});

it('doesn\'t recommend anything when levels are balanced', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/formulas/chlorine.test.ts
Expand Up @@ -66,7 +66,7 @@ describe('Chlorine Formula', () => {

// Assert
expect(Object.keys(res).length).toBe(2);
expect(res.m_acid).toBeCloseTo(17.4);
expect(res.m_acid).toBeCloseTo(26.1);
expect(res.phosphate_rem).toBeCloseTo(6);
});

Expand Down
2 changes: 1 addition & 1 deletion tests/formulas/ecosmarte.test.ts
Expand Up @@ -63,7 +63,7 @@ describe('ECOsmarte Formula', () => {

// Assert
expect(Object.keys(res).length).toBe(2);
expect(res.m_acid).toBeCloseTo(17.4);
expect(res.m_acid).toBeCloseTo(26.1);
expect(res.phosphate_rem).toBeCloseTo(6);
});

Expand Down
2 changes: 1 addition & 1 deletion tests/formulas/uv.test.ts
Expand Up @@ -64,7 +64,7 @@ describe('UV Formula', () => {

// Assert
expect(Object.keys(res).length).toBe(1);
expect(res.m_acid).toBeCloseTo(17.4);
expect(res.m_acid).toBeCloseTo(26.1);
});

it('doesn\'t recommend anything when levels are balanced', () => {
Expand Down
74 changes: 74 additions & 0 deletions tests/treatments/m_acid.test.ts
@@ -0,0 +1,74 @@
import { EffectiveTargetRanges } from '~/formulas/models/misc/Values';
import { m_acid } from '~/formulas/treatments/m_acid';
import { getPool } from '../helpers/testHelpers';

describe('Muriatic Acid treatment function', () => {
it('Returns null when there is no pH delta', () => {
// Arrange
const pool = getPool();
const targetLevels: EffectiveTargetRanges = { ph: { min: 7, max: 7.4 } };

// Act
const res = m_acid.function({
pool,
deltas: {},
extra: {
readings: {},
targets: targetLevels,
}
});

// Assert
expect(res).toBeNull();
});

// Arrange
const pool = getPool();
const targetLevels: EffectiveTargetRanges = {};

const testCases: any[] = [
// ph_delta, expected_m_acid
[0.0, null],
[-0.1, 0.00],
[-0.2, 9.00],
[-0.3, 13.50],
[-0.4, 17.40],
[-0.5, 21.75],
[-0.6, 26.10],
[-0.7, 29.40],
[-0.8, 32.40],
[-0.9, 36.45],
[-1.0, 40.50],
[-1.1, 44.55],
[-1.2, 48.60],
[-1.3, 52.65],
[-1.4, 56.70],
[-1.5, 60.75],
[-1.6, 64.80],
[-1.7, 68.85],
[-1.8, 72.90],
[-1.9, 75.00],
[-2.0, 75.00],
];

test.each(testCases)('deltas: { ph: %f }, should return %f ounces', (ph_delta: number, expected_m_acid: number | null) => {
// Act
const res = m_acid.function({
pool,
deltas: {
ph: ph_delta,
},
extra: {
readings: { ph: 7.4 - ph_delta },
targets: targetLevels
}
});

// Assert
if (expected_m_acid === null) {
expect(res).toBeNull();
} else {
expect(res?.amount).toBeCloseTo(expected_m_acid);
}
});
});