-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4079 from epam/3943-system-allow-to-create-atoms-…
…with-charge-value-out-or-range #3943 - System allow to create atoms with Charge value out or range
- Loading branch information
Showing
6 changed files
with
74 additions
and
12 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
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
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
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,50 @@ | ||
import { matchCharge } from 'src/script/ui/data/utils'; | ||
|
||
describe('data utils', () => { | ||
describe('matchCharge', () => { | ||
it('should return null for empty string', () => { | ||
const result = matchCharge(''); | ||
expect(result).toBeNull(); | ||
}); | ||
it('should return null for string with positive out of range charge', () => { | ||
const result = matchCharge('16'); | ||
expect(result).toBeNull(); | ||
}); | ||
it('should return null for string with negative out of range charge', () => { | ||
const result = matchCharge('-16'); | ||
expect(result).toBeNull(); | ||
}); | ||
it('should return expected matched array for string with zero charge', () => { | ||
const expectedMatchGroups = ['', '0', '']; | ||
const [, signBefore, absoluteValue, signAfter] = matchCharge('0') || []; | ||
expect([signBefore, absoluteValue, signAfter]).toEqual( | ||
expectedMatchGroups, | ||
); | ||
}); | ||
it('should return expected matched array for string with negative zero charge', () => { | ||
const expectedMatchGroups = ['-', '0', '']; | ||
const [, signBefore, absoluteValue, signAfter] = matchCharge('-0') || []; | ||
expect([signBefore, absoluteValue, signAfter]).toEqual( | ||
expectedMatchGroups, | ||
); | ||
}); | ||
it('should return expected matched array for string with negative zero charge after', () => { | ||
const expectedMatchGroups = ['', '0', '-']; | ||
const [, signBefore, absoluteValue, signAfter] = matchCharge('0-') || []; | ||
expect([signBefore, absoluteValue, signAfter]).toEqual( | ||
expectedMatchGroups, | ||
); | ||
}); | ||
it('should return expected matched array for string with two signs number', () => { | ||
const expectedMatchGroups = ['-', '0', '-']; | ||
const [, signBefore, absoluteValue, signAfter] = matchCharge('-0-') || []; | ||
expect([signBefore, absoluteValue, signAfter]).toEqual( | ||
expectedMatchGroups, | ||
); | ||
}); | ||
it('should return null for string with invalid number format', () => { | ||
const result = matchCharge('--0'); | ||
expect(result).toBeNull(); | ||
}); | ||
}); | ||
}); |
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,16 @@ | ||
import { atom } from './schema/struct-schema'; | ||
|
||
/** | ||
* Get match groups from string representation of charge. It returns RegExpExecArray for charges with values +-[0..15] | ||
* overwise returns null | ||
* | ||
* @example | ||
* matchCharge("16") === null | ||
* matchCharge("0") === [] | ||
* matchCharge("-1") === ["-1", "-", "1", ""] | ||
* matchCharge("15+") === ["15+", "", "15", "+"] | ||
*/ | ||
export function matchCharge(charge: string) { | ||
const regex = new RegExp(atom.properties.charge.pattern); | ||
return regex.exec(charge); | ||
} |
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