added coolprop
This commit is contained in:
94
src/coolprop-node/test/R448a.test.js
Normal file
94
src/coolprop-node/test/R448a.test.js
Normal file
@@ -0,0 +1,94 @@
|
||||
const coolprop = require('../src/index.js');
|
||||
|
||||
describe('R448a Real Values', () => {
|
||||
it('should calculate superheat correctly at -40°C saturation', async () => {
|
||||
const result = await coolprop.calculateSuperheat({
|
||||
temperature: -35, // 5K above saturation temp of -40°C
|
||||
pressure: 0, // saturation pressure at -40°C (from chart)
|
||||
refrigerant: 'R448a',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'psig'
|
||||
});
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.superheat - 5)).toBeLessThan(0.2); // Should be ~5K superheat
|
||||
});
|
||||
|
||||
it('should calculate superheat correctly at -20°C saturation', async () => {
|
||||
const result = await coolprop.calculateSuperheat({
|
||||
temperature: -15, // 5K above saturation temp of -20°C
|
||||
pressure: 21.0, // saturation pressure at -20°C (from chart)
|
||||
refrigerant: 'R448a',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'psig'
|
||||
});
|
||||
//console.log(result);
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.superheat - 5)).toBeLessThan(0.2); // Should be ~5K superheat
|
||||
});
|
||||
|
||||
it('should calculate subcooling correctly at 30°C saturation', async () => {
|
||||
const result = await coolprop.calculateSubcooling({
|
||||
temperature: 25, // 5K below saturation temp of 30°C
|
||||
pressure: 198.1, // saturation pressure at 30°C (from chart)
|
||||
refrigerant: 'R448a',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'psig'
|
||||
});
|
||||
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.subcooling - 5)).toBeLessThan(0.2); // Should be ~5K subcooling
|
||||
});
|
||||
|
||||
it('should calculate subcooling correctly at 40°C saturation', async () => {
|
||||
const result = await coolprop.calculateSubcooling({
|
||||
temperature: 35, // 5K below saturation temp of 40°C
|
||||
pressure: 258.0, // saturation pressure at 40°C (from chart)
|
||||
refrigerant: 'R448a',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'psig'
|
||||
});
|
||||
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.subcooling - 5)).toBeLessThan(0.2); // Should be ~5K subcooling
|
||||
});
|
||||
|
||||
it('should calculate zero superheat at saturation point', async () => {
|
||||
const result = await coolprop.calculateSuperheat({
|
||||
temperature: 0, // Exact saturation temperature
|
||||
pressure: 60.1, // Matching saturation pressure from chart
|
||||
refrigerant: 'R448a',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'psig'
|
||||
});
|
||||
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.superheat)).toBeLessThan(0.2); // Should be ~0K superheat
|
||||
});
|
||||
|
||||
it('should calculate zero subcooling at saturation point', async () => {
|
||||
const result = await coolprop.calculateSubcooling({
|
||||
temperature: 20, // Exact saturation temperature
|
||||
pressure: 148.5, // Matching saturation pressure from chart
|
||||
refrigerant: 'R448a',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'psig'
|
||||
});
|
||||
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.subcooling)).toBeLessThan(0.2); // Should be ~0K subcooling
|
||||
});
|
||||
|
||||
|
||||
it('It should also work with R448A (capital A)', async () => {
|
||||
const result = await coolprop.calculateSubcooling({
|
||||
temperature: 20, // Exact saturation temperature
|
||||
pressure: 148.5, // Matching saturation pressure from chart
|
||||
refrigerant: 'R448A',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'psig'
|
||||
});
|
||||
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.subcooling)).toBeLessThan(0.2); // Should be ~0K subcooling
|
||||
});
|
||||
});
|
||||
94
src/coolprop-node/test/R449a.test.js
Normal file
94
src/coolprop-node/test/R449a.test.js
Normal file
@@ -0,0 +1,94 @@
|
||||
const coolprop = require('../src/index.js');
|
||||
|
||||
describe('R449a Real Values', () => {
|
||||
it('should calculate superheat correctly at -40°C saturation', async () => {
|
||||
const result = await coolprop.calculateSuperheat({
|
||||
temperature: -35, // 5K above saturation temp of -40°C
|
||||
pressure: 0, // saturation pressure at -40°C (from chart)
|
||||
refrigerant: 'R449a',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'psig'
|
||||
});
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.superheat - 5)).toBeLessThan(0.2); // Should be ~5K superheat
|
||||
});
|
||||
|
||||
it('should calculate superheat correctly at -20°C saturation', async () => {
|
||||
const result = await coolprop.calculateSuperheat({
|
||||
temperature: -15, // 5K above saturation temp of -20°C
|
||||
pressure: 20.96, // saturation pressure at -20°C (from chart)
|
||||
refrigerant: 'R449a',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'psig'
|
||||
});
|
||||
//console.log(result);
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.superheat - 5)).toBeLessThan(0.2); // Should be ~5K superheat
|
||||
});
|
||||
|
||||
it('should calculate subcooling correctly at 30°C saturation', async () => {
|
||||
const result = await coolprop.calculateSubcooling({
|
||||
temperature: 25, // 5K below saturation temp of 30°C
|
||||
pressure: 195, // saturation pressure at 30°C (from chart)
|
||||
refrigerant: 'R449a',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'psig'
|
||||
});
|
||||
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.subcooling - 5)).toBeLessThan(0.2); // Should be ~5K subcooling
|
||||
});
|
||||
|
||||
it('should calculate subcooling correctly at 40°C saturation', async () => {
|
||||
const result = await coolprop.calculateSubcooling({
|
||||
temperature: 35, // 5K below saturation temp of 40°C
|
||||
pressure: 254.2, // saturation pressure at 40°C (from chart)
|
||||
refrigerant: 'R449a',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'psig'
|
||||
});
|
||||
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.subcooling - 5)).toBeLessThan(0.2); // Should be ~5K subcooling
|
||||
});
|
||||
|
||||
it('should calculate zero superheat at saturation point', async () => {
|
||||
const result = await coolprop.calculateSuperheat({
|
||||
temperature: 0, // Exact saturation temperature
|
||||
pressure: 74.05, // Matching saturation pressure from chart
|
||||
refrigerant: 'R449a',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'psig'
|
||||
});
|
||||
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.superheat)).toBeLessThan(0.2); // Should be ~0K superheat
|
||||
});
|
||||
|
||||
it('should calculate zero subcooling at saturation point', async () => {
|
||||
const result = await coolprop.calculateSubcooling({
|
||||
temperature: 20, // Exact saturation temperature
|
||||
pressure: 146.0, // Matching saturation pressure from chart
|
||||
refrigerant: 'R449a',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'psig'
|
||||
});
|
||||
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.subcooling)).toBeLessThan(0.2); // Should be ~0K subcooling
|
||||
});
|
||||
|
||||
|
||||
it('It should also work with R449A (capital A)', async () => {
|
||||
const result = await coolprop.calculateSubcooling({
|
||||
temperature: 20, // Exact saturation temperature
|
||||
pressure: 146.0, // Matching saturation pressure from chart
|
||||
refrigerant: 'R449A',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'psig'
|
||||
});
|
||||
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.subcooling)).toBeLessThan(0.2); // Should be ~0K subcooling
|
||||
});
|
||||
});
|
||||
97
src/coolprop-node/test/R507.test.js
Normal file
97
src/coolprop-node/test/R507.test.js
Normal file
@@ -0,0 +1,97 @@
|
||||
const coolprop = require('../src/index.js');
|
||||
|
||||
describe('R507 Real Values', () => {
|
||||
it('should calculate superheat correctly at -40°C saturation', async () => {
|
||||
const result = await coolprop.calculateSuperheat({
|
||||
temperature: -35, // 5K above saturation temp of -40°C
|
||||
pressure: 5.4, // saturation pressure at -40°C (from chart)
|
||||
refrigerant: 'R507a',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'psig'
|
||||
});
|
||||
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.superheat - 5)).toBeLessThan(0.1); // Should be ~5K superheat
|
||||
});
|
||||
|
||||
it('should calculate superheat correctly at -20°C saturation', async () => {
|
||||
const result = await coolprop.calculateSuperheat({
|
||||
temperature: -15, // 5K above saturation temp of -20°C
|
||||
pressure: 30.9, // saturation pressure at -20°C (from chart)
|
||||
refrigerant: 'R507a',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'psig'
|
||||
});
|
||||
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.superheat - 5)).toBeLessThan(0.1); // Should be ~5K superheat
|
||||
});
|
||||
|
||||
it('should calculate subcooling correctly at 30°C saturation', async () => {
|
||||
const result = await coolprop.calculateSubcooling({
|
||||
temperature: 25, // 5K below saturation temp of 30°C
|
||||
pressure: 196.9, // saturation pressure at 30°C (from chart)
|
||||
refrigerant: 'R507a',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'psig'
|
||||
});
|
||||
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.subcooling - 5)).toBeLessThan(0.1); // Should be ~5K subcooling
|
||||
});
|
||||
|
||||
|
||||
|
||||
it('should calculate subcooling correctly at 40°C saturation', async () => {
|
||||
const result = await coolprop.calculateSubcooling({
|
||||
temperature: 35, // 5K below saturation temp of 40°C
|
||||
pressure: 256.2, // saturation pressure at 40°C (from chart)
|
||||
refrigerant: 'R507a',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'psig'
|
||||
});
|
||||
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.subcooling - 5)).toBeLessThan(0.1); // Should be ~5K subcooling
|
||||
});
|
||||
|
||||
it('should calculate zero superheat at saturation point', async () => {
|
||||
const result = await coolprop.calculateSuperheat({
|
||||
temperature: 0, // Exact saturation temperature
|
||||
pressure: 75.8, // Matching saturation pressure from chart
|
||||
refrigerant: 'R507a',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'psig'
|
||||
});
|
||||
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.superheat)).toBeLessThan(0.1); // Should be ~0K superheat
|
||||
});
|
||||
|
||||
it('should calculate zero subcooling at saturation point', async () => {
|
||||
const result = await coolprop.calculateSubcooling({
|
||||
temperature: 20, // Exact saturation temperature
|
||||
pressure: 148, // Matching saturation pressure from chart
|
||||
refrigerant: 'R507a',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'psig'
|
||||
});
|
||||
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.subcooling)).toBeLessThan(0.1); // Should be ~0K subcooling
|
||||
});
|
||||
|
||||
it('should calculate subcooling correctly at 30°C saturation', async () => {
|
||||
const result = await coolprop.calculateSubcooling({
|
||||
temperature: 25, // 5K below saturation temp of 30°C
|
||||
pressure: 196.9, // saturation pressure at 30°C (from chart)
|
||||
refrigerant: 'R507',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'psig'
|
||||
});
|
||||
|
||||
expect(result.type).toBe('error');
|
||||
expect(result.message).toBe('Subcooling is infinity');
|
||||
expect(result.note).toBeDefined();
|
||||
});
|
||||
});
|
||||
55
src/coolprop-node/test/R744.C..test.js
Normal file
55
src/coolprop-node/test/R744.C..test.js
Normal file
@@ -0,0 +1,55 @@
|
||||
const coolprop = require('../src/index.js');
|
||||
|
||||
describe('R744 (CO2) Real Values', () => {
|
||||
it('should calculate superheat correctly at -40°C saturation', async () => {
|
||||
const result = await coolprop.calculateSuperheat({
|
||||
temperature: -35, // 5K above saturation temp of -40°C
|
||||
pressure: 9.03, // saturation pressure at -40°C (from chart)
|
||||
refrigerant: 'R744',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'bar'
|
||||
});
|
||||
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.superheat - 5)).toBeLessThan(0.1); // Should be ~5K superheat
|
||||
});
|
||||
|
||||
it('should calculate subcooling correctly at 0°C saturation', async () => {
|
||||
const result = await coolprop.calculateSubcooling({
|
||||
temperature: -5, // 5K below saturation temp of 0°C
|
||||
pressure: 33.84, // saturation pressure at 0°C (from chart)
|
||||
refrigerant: 'R744',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'bar'
|
||||
});
|
||||
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.subcooling - 5)).toBeLessThan(0.1); // Should be ~5K subcooling
|
||||
});
|
||||
|
||||
it('should calculate zero superheat at saturation point', async () => {
|
||||
const result = await coolprop.calculateSuperheat({
|
||||
temperature: -20, // Exact saturation temperature
|
||||
pressure: 18.68, // Matching saturation pressure from chart
|
||||
refrigerant: 'R744',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'bar'
|
||||
});
|
||||
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.superheat)).toBeLessThan(0.1); // Should be ~0K superheat
|
||||
});
|
||||
|
||||
it('should calculate zero subcooling at saturation point', async () => {
|
||||
const result = await coolprop.calculateSubcooling({
|
||||
temperature: 10, // Exact saturation temperature
|
||||
pressure: 44.01, // Matching saturation pressure from chart
|
||||
refrigerant: 'R744',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'bar'
|
||||
});
|
||||
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.subcooling)).toBeLessThan(0.1); // Should be ~0K subcooling
|
||||
});
|
||||
});
|
||||
55
src/coolprop-node/test/R744.F.test.js
Normal file
55
src/coolprop-node/test/R744.F.test.js
Normal file
@@ -0,0 +1,55 @@
|
||||
const coolprop = require('../src/index.js');
|
||||
|
||||
describe('R744 (CO2) Real Values', () => {
|
||||
it('should calculate superheat correctly at -40°F saturation', async () => {
|
||||
const result = await coolprop.calculateSuperheat({
|
||||
temperature: -35, // 5°F above saturation temp of -40°F
|
||||
pressure: 131, // saturation pressure at -40°F (from chart)
|
||||
refrigerant: 'R744',
|
||||
tempUnit: 'F', // Changed to F
|
||||
pressureUnit: 'psig'
|
||||
});
|
||||
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.superheat - 5)).toBeLessThan(0.1); // Should be ~5°F superheat
|
||||
});
|
||||
|
||||
it('should calculate subcooling correctly at 32°F saturation', async () => {
|
||||
const result = await coolprop.calculateSubcooling({
|
||||
temperature: 27, // 5°F below saturation temp of 32°F
|
||||
pressure: 490.8, // saturation pressure at 32°F (from chart)
|
||||
refrigerant: 'R744',
|
||||
tempUnit: 'F', // Changed to F
|
||||
pressureUnit: 'psig'
|
||||
});
|
||||
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.subcooling - 5)).toBeLessThan(0.1); // Should be ~5°F subcooling
|
||||
});
|
||||
|
||||
it('should calculate zero superheat at saturation point', async () => {
|
||||
const result = await coolprop.calculateSuperheat({
|
||||
temperature: 32, // Exact saturation temperature
|
||||
pressure: 490.8, // Matching saturation pressure from chart
|
||||
refrigerant: 'R744',
|
||||
tempUnit: 'F', // Changed to F
|
||||
pressureUnit: 'psig'
|
||||
});
|
||||
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.superheat)).toBeLessThan(0.1); // Should be ~0°F superheat
|
||||
});
|
||||
|
||||
it('should calculate zero subcooling at saturation point', async () => {
|
||||
const result = await coolprop.calculateSubcooling({
|
||||
temperature: 32, // Exact saturation temperature
|
||||
pressure: 490.8, // Matching saturation pressure from chart
|
||||
refrigerant: 'R744',
|
||||
tempUnit: 'F', // Changed to F
|
||||
pressureUnit: 'psig'
|
||||
});
|
||||
|
||||
expect(result.type).toBe('success');
|
||||
expect(Math.abs(result.subcooling)).toBeLessThan(0.1); // Should be ~0°F subcooling
|
||||
});
|
||||
});
|
||||
296
src/coolprop-node/test/nodeprop.test.js
Normal file
296
src/coolprop-node/test/nodeprop.test.js
Normal file
@@ -0,0 +1,296 @@
|
||||
const coolprop = require('../src/index.js');
|
||||
|
||||
describe('CoolProp Wrapper', () => {
|
||||
describe('Initialization', () => {
|
||||
it('should fail without refrigerant', async () => {
|
||||
const result = await coolprop.init({});
|
||||
expect(result.type).toBe('error');
|
||||
expect(result.message).toContain('Refrigerant must be specified');
|
||||
});
|
||||
|
||||
it('should fail with invalid temperature unit', async () => {
|
||||
const result = await coolprop.init({ refrigerant: 'R404A', tempUnit: 'X' });
|
||||
expect(result.type).toBe('error');
|
||||
expect(result.message).toContain('Invalid temperature unit');
|
||||
});
|
||||
|
||||
it('should fail with invalid pressure unit', async () => {
|
||||
const result = await coolprop.init({ refrigerant: 'R404A', pressureUnit: 'X' });
|
||||
expect(result.type).toBe('error');
|
||||
expect(result.message).toContain('Invalid pressure unit');
|
||||
});
|
||||
|
||||
it('should succeed with valid config', async () => {
|
||||
const result = await coolprop.init({
|
||||
refrigerant: 'R404A',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'bar'
|
||||
});
|
||||
console.log(result);
|
||||
expect(result.type).toBe('success');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Auto-initialization', () => {
|
||||
it('should work without explicit init', async () => {
|
||||
const result = await coolprop.calculateSuperheat({
|
||||
temperature: 25,
|
||||
pressure: 10,
|
||||
refrigerant: 'R404A',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'bar'
|
||||
});
|
||||
expect(result.type).toBe('success');
|
||||
expect(result.superheat).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Unit Conversions', () => {
|
||||
it('should correctly convert temperature units', async () => {
|
||||
const resultC = await coolprop.getSaturationTemperature({
|
||||
pressure: 10,
|
||||
refrigerant: 'R404A',
|
||||
pressureUnit: 'bar',
|
||||
tempUnit: 'C'
|
||||
});
|
||||
|
||||
const resultF = await coolprop.getSaturationTemperature({
|
||||
pressure: 10,
|
||||
refrigerant: 'R404A',
|
||||
pressureUnit: 'bar',
|
||||
tempUnit: 'F'
|
||||
});
|
||||
|
||||
const resultK = await coolprop.getSaturationTemperature({
|
||||
pressure: 10,
|
||||
refrigerant: 'R404A',
|
||||
pressureUnit: 'bar',
|
||||
tempUnit: 'K'
|
||||
});
|
||||
|
||||
expect(Math.abs((resultC.temperature * 9/5 + 32) - resultF.temperature)).toBeLessThan(0.01);
|
||||
expect(Math.abs((resultC.temperature + 273.15) - resultK.temperature)).toBeLessThan(0.01);
|
||||
});
|
||||
|
||||
it('should correctly convert pressure units', async () => {
|
||||
const resultBar = await coolprop.getSaturationPressure({
|
||||
temperature: 25,
|
||||
refrigerant: 'R404A',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'bar'
|
||||
});
|
||||
|
||||
const resultPsi = await coolprop.getSaturationPressure({
|
||||
temperature: 25,
|
||||
refrigerant: 'R404A',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'psi'
|
||||
});
|
||||
|
||||
expect(Math.abs((resultBar.pressure * 14.5038) - resultPsi.pressure)).toBeLessThan(0.1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Refrigerant Calculations', () => {
|
||||
const refrigerants = ['R404A', 'R134a', 'R507A', 'R744'];
|
||||
|
||||
refrigerants.forEach(refrigerant => {
|
||||
describe(refrigerant, () => {
|
||||
it('should calculate superheat', async () => {
|
||||
const result = await coolprop.calculateSuperheat({
|
||||
temperature: 25,
|
||||
pressure: 10,
|
||||
refrigerant,
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'bar'
|
||||
});
|
||||
expect(result.type).toBe('success');
|
||||
expect(result.superheat).toBeDefined();
|
||||
expect(result.refrigerant).toBe(refrigerant);
|
||||
expect(result.units).toEqual(expect.objectContaining({
|
||||
temperature: 'C',
|
||||
pressure: 'bar'
|
||||
}));
|
||||
});
|
||||
|
||||
it('should calculate subcooling', async () => {
|
||||
const result = await coolprop.calculateSubcooling({
|
||||
temperature: 20,
|
||||
pressure: 20,
|
||||
refrigerant,
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'bar'
|
||||
});
|
||||
expect(result.type).toBe('success');
|
||||
expect(result.subcooling).toBeDefined();
|
||||
expect(result.refrigerant).toBe(refrigerant);
|
||||
});
|
||||
|
||||
it('should get all properties', async () => {
|
||||
const result = await coolprop.getProperties({
|
||||
temperature: 25,
|
||||
pressure: 10,
|
||||
refrigerant,
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'bar'
|
||||
});
|
||||
expect(result.type).toBe('success');
|
||||
expect(result.properties).toBeDefined();
|
||||
expect(result.refrigerant).toBe(refrigerant);
|
||||
|
||||
// Check all required properties exist
|
||||
const requiredProps = [
|
||||
'temperature', 'pressure', 'density', 'enthalpy',
|
||||
'entropy', 'quality', 'conductivity', 'viscosity', 'specificHeat'
|
||||
];
|
||||
requiredProps.forEach(prop => {
|
||||
expect(result.properties[prop]).toBeDefined();
|
||||
expect(typeof result.properties[prop]).toBe('number');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Default Override Behavior', () => {
|
||||
beforeAll(async () => {
|
||||
await coolprop.init({
|
||||
refrigerant: 'R404A',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'bar'
|
||||
});
|
||||
});
|
||||
|
||||
it('should use defaults when no overrides provided', async () => {
|
||||
const result = await coolprop.calculateSuperheat({
|
||||
temperature: 25,
|
||||
pressure: 10
|
||||
});
|
||||
expect(result.refrigerant).toBe('R404A');
|
||||
expect(result.units.temperature).toBe('C');
|
||||
expect(result.units.pressure).toBe('bar');
|
||||
});
|
||||
|
||||
it('should allow refrigerant override', async () => {
|
||||
const result = await coolprop.calculateSuperheat({
|
||||
temperature: 25,
|
||||
pressure: 10,
|
||||
refrigerant: 'R134a'
|
||||
});
|
||||
expect(result.refrigerant).toBe('R134a');
|
||||
});
|
||||
|
||||
it('should allow unit overrides', async () => {
|
||||
const result = await coolprop.calculateSuperheat({
|
||||
temperature: 77,
|
||||
pressure: 145,
|
||||
tempUnit: 'F',
|
||||
pressureUnit: 'psi'
|
||||
});
|
||||
expect(result.units.temperature).toBe('F');
|
||||
expect(result.units.pressure).toBe('psi');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Default Settings Management', () => {
|
||||
it('should allow updating defaults after initialization', async () => {
|
||||
// Initial setup
|
||||
await coolprop.init({
|
||||
refrigerant: 'R404A',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'bar'
|
||||
});
|
||||
|
||||
// Update defaults
|
||||
const updateResult = await coolprop.init({
|
||||
refrigerant: 'R134a',
|
||||
tempUnit: 'F',
|
||||
pressureUnit: 'psi'
|
||||
});
|
||||
|
||||
expect(updateResult.type).toBe('success');
|
||||
expect(updateResult.message).toBe('Default settings updated');
|
||||
|
||||
// Verify new defaults are used
|
||||
const result = await coolprop.calculateSuperheat({
|
||||
temperature: 77,
|
||||
pressure: 145
|
||||
});
|
||||
|
||||
expect(result.refrigerant).toBe('R134a');
|
||||
expect(result.units.temperature).toBe('F');
|
||||
expect(result.units.pressure).toBe('psi');
|
||||
});
|
||||
|
||||
it('should update the coolprop instance if refrigerant is changed', async () => {
|
||||
// Set initial defaults
|
||||
await coolprop.init({
|
||||
refrigerant: 'R404A',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'bar'
|
||||
});
|
||||
|
||||
const config = await coolprop.getConfig();
|
||||
|
||||
// First call with overrides
|
||||
const result1 = await coolprop.calculateSuperheat({
|
||||
temperature: 25,
|
||||
pressure: 10,
|
||||
refrigerant: 'R507A',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'bar'
|
||||
});
|
||||
|
||||
// Second call using defaults
|
||||
const result2 = await coolprop.calculateSuperheat({
|
||||
temperature: 25,
|
||||
pressure: 10
|
||||
});
|
||||
const config2 = await coolprop.getConfig();
|
||||
expect(config.refrigerant).toBe('R404A');
|
||||
expect(config2.refrigerant).toBe('R507A');
|
||||
expect(result1.refrigerant).toBe('R507A');
|
||||
expect(result2.refrigerant).toBe('R507A');
|
||||
});
|
||||
|
||||
it('should allow partial updates of defaults', async () => {
|
||||
// Initial setup
|
||||
await coolprop.init({
|
||||
refrigerant: 'R404A',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'bar'
|
||||
});
|
||||
|
||||
// Update only temperature unit
|
||||
await coolprop.init({
|
||||
tempUnit: 'F'
|
||||
});
|
||||
|
||||
const result = await coolprop.calculateSuperheat({
|
||||
temperature: 77,
|
||||
pressure: 10
|
||||
});
|
||||
|
||||
expect(result.refrigerant).toBe('R404A'); // unchanged
|
||||
expect(result.units.temperature).toBe('F'); // updated
|
||||
expect(result.units.pressure).toBe('bar'); // unchanged
|
||||
});
|
||||
|
||||
it('should validate units when updating defaults', async () => {
|
||||
await coolprop.init({
|
||||
refrigerant: 'R404A',
|
||||
tempUnit: 'C',
|
||||
pressureUnit: 'bar'
|
||||
});
|
||||
|
||||
const result = await coolprop.init({
|
||||
tempUnit: 'X' // invalid unit
|
||||
});
|
||||
|
||||
expect(result.type).toBe('error');
|
||||
expect(result.message).toContain('Invalid temperature unit');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
58
src/coolprop-node/test/pressure-conversions.test.js
Normal file
58
src/coolprop-node/test/pressure-conversions.test.js
Normal file
@@ -0,0 +1,58 @@
|
||||
const coolprop = require('../src/index.js');
|
||||
|
||||
describe('Pressure Conversion Chain Tests', () => {
|
||||
|
||||
test('bar -> pa -> bara -> pa -> bar conversion chain', () => {
|
||||
const startValue = 2; // 2 bar gauge
|
||||
|
||||
const toPa = coolprop._convertPressureToPa(startValue, 'bar');
|
||||
// console.log('bar to Pa:', toPa);
|
||||
|
||||
const toBara = coolprop._convertPressureFromPa(toPa, 'bara');
|
||||
// console.log('Pa to bara:', toBara);
|
||||
|
||||
const backToPa = coolprop._convertPressureToPa(toBara, 'bara');
|
||||
// console.log('bara to Pa:', backToPa);
|
||||
|
||||
const backToBar = coolprop._convertPressureFromPa(backToPa, 'bar');
|
||||
// console.log('Pa to bar:', backToBar);
|
||||
|
||||
expect(Math.round(backToBar * 1000) / 1000).toBe(startValue);
|
||||
});
|
||||
|
||||
test('psi -> pa -> psia -> pa -> psi conversion chain', () => {
|
||||
const startValue = 30; // 30 psi gauge
|
||||
|
||||
const toPa = coolprop._convertPressureToPa(startValue, 'psi');
|
||||
// console.log('psi to Pa:', toPa);
|
||||
|
||||
const toPsia = coolprop._convertPressureFromPa(toPa, 'psia');
|
||||
// console.log('Pa to psia:', toPsia);
|
||||
|
||||
const backToPa = coolprop._convertPressureToPa(toPsia, 'psia');
|
||||
// console.log('psia to Pa:', backToPa);
|
||||
|
||||
const backToPsi = coolprop._convertPressureFromPa(backToPa, 'psi');
|
||||
// console.log('Pa to psi:', backToPsi);
|
||||
|
||||
expect(Math.round(backToPsi * 1000) / 1000).toBe(startValue);
|
||||
});
|
||||
|
||||
test('kpa -> pa -> kpaa -> pa -> kpa conversion chain', () => {
|
||||
const startValue = 200; // 200 kPa gauge
|
||||
|
||||
const toPa = coolprop._convertPressureToPa(startValue, 'kpa');
|
||||
// console.log('kpa to Pa:', toPa);
|
||||
|
||||
const toKpaa = coolprop._convertPressureFromPa(toPa, 'kpaa');
|
||||
// console.log('Pa to kpaa:', toKpaa);
|
||||
|
||||
const backToPa = coolprop._convertPressureToPa(toKpaa, 'kpaa');
|
||||
// console.log('kpaa to Pa:', backToPa);
|
||||
|
||||
const backToKpa = coolprop._convertPressureFromPa(backToPa, 'kpa');
|
||||
// console.log('Pa to kpa:', backToKpa);
|
||||
|
||||
expect(Math.round(backToKpa * 1000) / 1000).toBe(startValue);
|
||||
});
|
||||
});
|
||||
50
src/coolprop-node/test/propsSI.test.js
Normal file
50
src/coolprop-node/test/propsSI.test.js
Normal file
@@ -0,0 +1,50 @@
|
||||
const coolProp = require('../src/index.js');
|
||||
|
||||
describe('PropsSI Direct Access', () => {
|
||||
let PropsSI;
|
||||
|
||||
beforeAll(async () => {
|
||||
// Get the PropsSI function
|
||||
PropsSI = await coolProp.getPropsSI();
|
||||
});
|
||||
|
||||
test('should initialize and return PropsSI function', async () => {
|
||||
expect(typeof PropsSI).toBe('function');
|
||||
});
|
||||
|
||||
test('should calculate saturation temperature of R134a at 1 bar', () => {
|
||||
const pressure = 100000; // 1 bar in Pa
|
||||
const temp = PropsSI('T', 'P', pressure, 'Q', 0, 'R134a');
|
||||
expect(temp).toBeCloseTo(246.79, 1); // ~246.79 K at 1 bar
|
||||
});
|
||||
|
||||
test('should calculate density of R134a at specific conditions', () => {
|
||||
const temp = 300; // 300 K
|
||||
const pressure = 100000; // 1 bar in Pa
|
||||
const density = PropsSI('D', 'T', temp, 'P', pressure, 'R134a');
|
||||
expect(density).toBeGreaterThan(0)
|
||||
expect(density).toBeLessThan(Infinity);
|
||||
});
|
||||
|
||||
test('should throw error for invalid refrigerant', () => {
|
||||
const temp = 300;
|
||||
const pressure = 100000;
|
||||
expect(() => {
|
||||
let result = PropsSI('D', 'T', temp, 'P', pressure, 'INVALID_REFRIGERANT');
|
||||
if(result == Infinity) {
|
||||
throw new Error('Infinity due to invalid refrigerant');
|
||||
}
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
test('should throw error for invalid input parameter', () => {
|
||||
const temp = 300;
|
||||
const pressure = 100000;
|
||||
expect(() => {
|
||||
let result = PropsSI('INVALID_PARAM', 'T', temp, 'P', pressure, 'R134a');
|
||||
if(result == Infinity) {
|
||||
throw new Error('Infinity due to invalid input parameter');
|
||||
}
|
||||
}).toThrow();
|
||||
});
|
||||
});
|
||||
128
src/coolprop-node/test/temperature-conversions.test.js
Normal file
128
src/coolprop-node/test/temperature-conversions.test.js
Normal file
@@ -0,0 +1,128 @@
|
||||
const coolprop = require('../src/index.js');
|
||||
|
||||
describe('Temperature Conversion Tests', () => {
|
||||
|
||||
describe('Regular Temperature Conversions', () => {
|
||||
const testCases = [
|
||||
{
|
||||
startUnit: 'C',
|
||||
startValue: 25,
|
||||
expectedK: 298.15,
|
||||
conversions: {
|
||||
F: 77,
|
||||
K: 298.15,
|
||||
C: 25
|
||||
}
|
||||
},
|
||||
{
|
||||
startUnit: 'F',
|
||||
startValue: 77,
|
||||
expectedK: 298.15,
|
||||
conversions: {
|
||||
F: 77,
|
||||
K: 298.15,
|
||||
C: 25
|
||||
}
|
||||
},
|
||||
{
|
||||
startUnit: 'K',
|
||||
startValue: 298.15,
|
||||
expectedK: 298.15,
|
||||
conversions: {
|
||||
F: 77,
|
||||
K: 298.15,
|
||||
C: 25
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
testCases.forEach(({ startUnit, startValue, expectedK, conversions }) => {
|
||||
test(`${startValue}${startUnit} conversion chain`, () => {
|
||||
// First convert to Kelvin
|
||||
const toK = coolprop._convertTempToK(startValue, startUnit);
|
||||
expect(Math.round(toK * 100) / 100).toBe(expectedK);
|
||||
|
||||
// Then convert from Kelvin to each unit
|
||||
Object.entries(conversions).forEach(([unit, expected]) => {
|
||||
const converted = coolprop._convertTempFromK(toK, unit);
|
||||
expect(Math.round(converted * 100) / 100).toBe(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Delta Temperature Conversions', () => {
|
||||
const testCases = [
|
||||
{
|
||||
startValue: 10, // 10K temperature difference
|
||||
expected: {
|
||||
K: 10,
|
||||
C: 10,
|
||||
F: 18 // 10K = 18°F difference
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
testCases.forEach(({ startValue, expected }) => {
|
||||
test(`${startValue}K delta conversion to all units`, () => {
|
||||
Object.entries(expected).forEach(([unit, expectedValue]) => {
|
||||
const converted = coolprop._convertDeltaTempFromK(startValue, unit);
|
||||
expect(Math.round(converted * 100) / 100).toBe(expectedValue);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Common Temperature Points', () => {
|
||||
const commonPoints = [
|
||||
{
|
||||
description: 'Water freezing point',
|
||||
C: 0,
|
||||
F: 32,
|
||||
K: 273.15
|
||||
},
|
||||
{
|
||||
description: 'Water boiling point',
|
||||
C: 100,
|
||||
F: 212,
|
||||
K: 373.15
|
||||
},
|
||||
{
|
||||
description: 'Room temperature',
|
||||
C: 20,
|
||||
F: 68,
|
||||
K: 293.15
|
||||
},
|
||||
{
|
||||
description: 'Typical refrigeration evaporator',
|
||||
C: 5,
|
||||
F: 41,
|
||||
K: 278.15
|
||||
},
|
||||
{
|
||||
description: 'Typical refrigeration condenser',
|
||||
C: 35,
|
||||
F: 95,
|
||||
K: 308.15
|
||||
}
|
||||
];
|
||||
|
||||
commonPoints.forEach(point => {
|
||||
test(`${point.description} conversions`, () => {
|
||||
// Test conversion to Kelvin from each unit
|
||||
const fromC = coolprop._convertTempToK(point.C, 'C');
|
||||
const fromF = coolprop._convertTempToK(point.F, 'F');
|
||||
|
||||
expect(Math.round(fromC * 100) / 100).toBe(point.K);
|
||||
expect(Math.round(fromF * 100) / 100).toBe(point.K);
|
||||
|
||||
// Test conversion from Kelvin to each unit
|
||||
const toC = coolprop._convertTempFromK(point.K, 'C');
|
||||
const toF = coolprop._convertTempFromK(point.K, 'F');
|
||||
|
||||
expect(Math.round(toC * 100) / 100).toBe(point.C);
|
||||
expect(Math.round(toF * 100) / 100).toBe(point.F);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user