Comparing version
{ | ||
"name": "mf-parser", | ||
"version": "0.12.0", | ||
"version": "0.13.0", | ||
"description": "", | ||
@@ -27,4 +27,3 @@ "main": "src/index.js", | ||
"jest-matcher-deep-close-to": "^1.3.0" | ||
}, | ||
"gitHead": "aa2e6571c5f7121dda616b7d6920b7a653a8f9c7" | ||
} | ||
} |
@@ -12,8 +12,10 @@ 'use strict'; | ||
{ x: 12, y: 0.9893 }, | ||
{ x: 13.00335483507, y: 0.0107 } | ||
{ x: 13.00335483507, y: 0.0107 }, | ||
]); | ||
expect(info.isotopes[1].distribution).toStrictEqual([{ x: 13.00335483507, y: 1 }]); | ||
expect(info.isotopes[1].distribution).toStrictEqual([ | ||
{ x: 13.00335483507, y: 1 }, | ||
]); | ||
expect(info.isotopes[2].distribution).toStrictEqual([ | ||
{ x: 12, y: 0.5 }, | ||
{ x: 13.00335483507, y: 0.5 } | ||
{ x: 13.00335483507, y: 0.5 }, | ||
]); | ||
@@ -20,0 +22,0 @@ }); |
@@ -186,3 +186,3 @@ 'use strict'; | ||
test('test unsaturation with charges', () => { | ||
test('unsaturation with charges', () => { | ||
expect(new MF('CH4').getInfo().unsaturation).toBe(0); | ||
@@ -226,3 +226,3 @@ expect(new MF('C10H22O').getInfo().unsaturation).toBe(0); | ||
test('MF of DNA HODampDtmpDcmpDgmpH ', () => { | ||
test('MF of DNA HODampDtmpDcmpDgmpH', () => { | ||
let mf = new MF('HODampDtmpDgmpDcmpH'); | ||
@@ -240,3 +240,3 @@ let info = mf.getInfo(); | ||
test('MF of RNA HOAmpUmpH ', () => { | ||
test('MF of RNA HOAmpUmpH', () => { | ||
let mf = new MF('HOAmpUmpH'); | ||
@@ -243,0 +243,0 @@ let info = mf.getInfo(); |
@@ -6,4 +6,10 @@ 'use strict'; | ||
let tests = { | ||
C10: [{ kind: 'atom', value: 'C' }, { kind: 'multiplier', value: 10 }], | ||
'C-1': [{ kind: 'atom', value: 'C' }, { kind: 'multiplier', value: -1 }], | ||
C10: [ | ||
{ kind: 'atom', value: 'C' }, | ||
{ kind: 'multiplier', value: 10 }, | ||
], | ||
'C-1': [ | ||
{ kind: 'atom', value: 'C' }, | ||
{ kind: 'multiplier', value: -1 }, | ||
], | ||
'C1-10': [ | ||
@@ -13,7 +19,16 @@ { kind: 'atom', value: 'C' }, | ||
], | ||
'2H': [{ kind: 'preMultiplier', value: 2 }, { kind: 'atom', value: 'H' }], | ||
'2H': [ | ||
{ kind: 'preMultiplier', value: 2 }, | ||
{ kind: 'atom', value: 'H' }, | ||
], | ||
'[13C]': [{ kind: 'isotope', value: { atom: 'C', isotope: 13 } }], | ||
'[2H]': [{ kind: 'isotope', value: { atom: 'H', isotope: 2 } }], | ||
'C+': [{ kind: 'atom', value: 'C' }, { kind: 'charge', value: 1 }], | ||
'C-': [{ kind: 'atom', value: 'C' }, { kind: 'charge', value: -1 }], | ||
'C+': [ | ||
{ kind: 'atom', value: 'C' }, | ||
{ kind: 'charge', value: 1 }, | ||
], | ||
'C-': [ | ||
{ kind: 'atom', value: 'C' }, | ||
{ kind: 'charge', value: -1 }, | ||
], | ||
'C-H': [ | ||
@@ -24,4 +39,10 @@ { kind: 'atom', value: 'C' }, | ||
], | ||
'C++': [{ kind: 'atom', value: 'C' }, { kind: 'charge', value: 2 }], | ||
'C--': [{ kind: 'atom', value: 'C' }, { kind: 'charge', value: -2 }], | ||
'C++': [ | ||
{ kind: 'atom', value: 'C' }, | ||
{ kind: 'charge', value: 2 }, | ||
], | ||
'C--': [ | ||
{ kind: 'atom', value: 'C' }, | ||
{ kind: 'charge', value: -2 }, | ||
], | ||
'C2+': [ | ||
@@ -32,8 +53,26 @@ { kind: 'atom', value: 'C' }, | ||
], | ||
'C(2+)': [{ kind: 'atom', value: 'C' }, { kind: 'charge', value: 2 }], | ||
'C(++)': [{ kind: 'atom', value: 'C' }, { kind: 'charge', value: 2 }], | ||
'C(+2)': [{ kind: 'atom', value: 'C' }, { kind: 'charge', value: 2 }], | ||
'C(2-)': [{ kind: 'atom', value: 'C' }, { kind: 'charge', value: -2 }], | ||
'C(-2)': [{ kind: 'atom', value: 'C' }, { kind: 'charge', value: -2 }], | ||
'C(--)': [{ kind: 'atom', value: 'C' }, { kind: 'charge', value: -2 }], | ||
'C(2+)': [ | ||
{ kind: 'atom', value: 'C' }, | ||
{ kind: 'charge', value: 2 }, | ||
], | ||
'C(++)': [ | ||
{ kind: 'atom', value: 'C' }, | ||
{ kind: 'charge', value: 2 }, | ||
], | ||
'C(+2)': [ | ||
{ kind: 'atom', value: 'C' }, | ||
{ kind: 'charge', value: 2 }, | ||
], | ||
'C(2-)': [ | ||
{ kind: 'atom', value: 'C' }, | ||
{ kind: 'charge', value: -2 }, | ||
], | ||
'C(-2)': [ | ||
{ kind: 'atom', value: 'C' }, | ||
{ kind: 'charge', value: -2 }, | ||
], | ||
'C(--)': [ | ||
{ kind: 'atom', value: 'C' }, | ||
{ kind: 'charge', value: -2 }, | ||
], | ||
'(H+)': [ | ||
@@ -45,3 +84,6 @@ { kind: 'openingParenthesis', value: '(' }, | ||
], | ||
C$ABC: [{ kind: 'atom', value: 'C' }, { kind: 'comment', value: 'ABC' }], | ||
C$ABC: [ | ||
{ kind: 'atom', value: 'C' }, | ||
{ kind: 'comment', value: 'ABC' }, | ||
], | ||
'C(-1)(-3)': [ | ||
@@ -168,3 +210,3 @@ { kind: 'atom', value: 'C' }, | ||
test.each(Object.keys(tests))('parse molecular formula %s', function (key) { | ||
test.each(Object.keys(tests))('parse molecular formula %s', function(key) { | ||
let parsed = parse(key); | ||
@@ -174,3 +216,3 @@ expect(parsed).toMatchObject(tests[key]); | ||
test('not same opening and closing parenthesis', function () { | ||
test('not same opening and closing parenthesis', function() { | ||
expect(() => { | ||
@@ -177,0 +219,0 @@ parse('C('); |
@@ -5,3 +5,3 @@ 'use strict'; | ||
test('formatCharge', function () { | ||
test('formatCharge', function() { | ||
expect(formatCharge(-2)).toBe('-2'); | ||
@@ -8,0 +8,0 @@ expect(formatCharge(-1)).toBe('-1'); |
@@ -5,3 +5,3 @@ 'use strict'; | ||
test('getCharge', function () { | ||
test('getCharge', function() { | ||
expect(getCharge('---')).toBe(-3); | ||
@@ -8,0 +8,0 @@ expect(getCharge('+++')).toBe(3); |
@@ -6,9 +6,21 @@ 'use strict'; | ||
mf: 'C10', | ||
parsed: [{ kind: 'atom', value: 'C' }, { kind: 'multiplier', value: 10 }], | ||
result: [{ kind: 'text', value: 'C' }, { kind: 'subscript', value: '10' }], | ||
parsed: [ | ||
{ kind: 'atom', value: 'C' }, | ||
{ kind: 'multiplier', value: 10 }, | ||
], | ||
result: [ | ||
{ kind: 'text', value: 'C' }, | ||
{ kind: 'subscript', value: '10' }, | ||
], | ||
}, | ||
{ | ||
mf: 'C-1', | ||
parsed: [{ kind: 'atom', value: 'C' }, { kind: 'multiplier', value: -1 }], | ||
result: [{ kind: 'text', value: 'C' }, { kind: 'subscript', value: '-1' }], | ||
parsed: [ | ||
{ kind: 'atom', value: 'C' }, | ||
{ kind: 'multiplier', value: -1 }, | ||
], | ||
result: [ | ||
{ kind: 'text', value: 'C' }, | ||
{ kind: 'subscript', value: '-1' }, | ||
], | ||
}, | ||
@@ -28,3 +40,6 @@ { | ||
mf: '2H', | ||
parsed: [{ kind: 'preMultiplier', value: 2 }, { kind: 'atom', value: 'H' }], | ||
parsed: [ | ||
{ kind: 'preMultiplier', value: 2 }, | ||
{ kind: 'atom', value: 'H' }, | ||
], | ||
result: [{ kind: 'text', value: '2H' }], | ||
@@ -35,7 +50,13 @@ }, | ||
parsed: [{ kind: 'isotope', value: { atom: 'C', isotope: 13 } }], | ||
result: [{ kind: 'superscript', value: 13 }, { kind: 'text', value: 'C' }], | ||
result: [ | ||
{ kind: 'superscript', value: 13 }, | ||
{ kind: 'text', value: 'C' }, | ||
], | ||
}, | ||
{ | ||
mf: 'C++', | ||
parsed: [{ kind: 'atom', value: 'C' }, { kind: 'charge', value: 2 }], | ||
parsed: [ | ||
{ kind: 'atom', value: 'C' }, | ||
{ kind: 'charge', value: 2 }, | ||
], | ||
result: [ | ||
@@ -94,5 +115,5 @@ { kind: 'text', value: 'C' }, | ||
test.each(tests)('toDisplay', function (aTest) { | ||
test.each(tests)('toDisplay', function(aTest) { | ||
let display = toDisplay(aTest.parsed); | ||
expect(display).toMatchObject(aTest.result); | ||
}); |
@@ -12,3 +12,3 @@ 'use strict'; | ||
mf: '2C(C(C2)2)3', | ||
result: [[{ kind: 'atom', value: 'C', multiplier: 32 }]] | ||
result: [[{ kind: 'atom', value: 'C', multiplier: 32 }]], | ||
}, | ||
@@ -20,4 +20,4 @@ { | ||
[{ kind: 'atom', value: 'C', multiplier: 2 }], | ||
[{ kind: 'atom', value: 'C', multiplier: 4 }] | ||
] | ||
[{ kind: 'atom', value: 'C', multiplier: 4 }], | ||
], | ||
}, | ||
@@ -30,9 +30,9 @@ { | ||
{ kind: 'atom', value: 'H', multiplier: 15 }, | ||
{ kind: 'atom', value: 'N', multiplier: 1 } | ||
{ kind: 'atom', value: 'N', multiplier: 1 }, | ||
], | ||
[ | ||
{ kind: 'atom', value: 'H', multiplier: 1 }, | ||
{ kind: 'atom', value: 'Cl', multiplier: 1 } | ||
] | ||
] | ||
{ kind: 'atom', value: 'Cl', multiplier: 1 }, | ||
], | ||
], | ||
}, | ||
@@ -44,10 +44,12 @@ { | ||
{ kind: 'atom', value: 'C', multiplier: 3 }, | ||
{ kind: 'isotope', value: { atom: 'C', isotope: 13 }, multiplier: 6 } | ||
] | ||
] | ||
{ kind: 'isotope', value: { atom: 'C', isotope: 13 }, multiplier: 6 }, | ||
], | ||
], | ||
}, | ||
{ | ||
mf: 'D', | ||
result: [[{ kind: 'isotope', value: { atom: 'H', isotope: 2 }, multiplier: 1 }]] | ||
} | ||
result: [ | ||
[{ kind: 'isotope', value: { atom: 'H', isotope: 2 }, multiplier: 1 }], | ||
], | ||
}, | ||
]; | ||
@@ -57,3 +59,3 @@ | ||
test.each(tests)('toParts %p', function (aTest) { | ||
test.each(tests)('toParts %p', function(aTest) { | ||
let parsed = parse(aTest.mf); | ||
@@ -60,0 +62,0 @@ let parts = toParts(parsed); |
62497
4.23%36
5.88%2055
7.7%