-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7fca7b
commit d605cf6
Showing
13 changed files
with
151 additions
and
4 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
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,36 @@ | ||
import mock from '../__fixtures__/mock'; | ||
|
||
import Complex from '../complex'; | ||
import div from './div'; | ||
import mul from './mul'; | ||
import sub from './sub'; | ||
import trunc from './trunc'; | ||
import sut from './mod'; | ||
|
||
jest.mock('./div'); | ||
jest.mock('./sub'); | ||
jest.mock('./mul'); | ||
jest.mock('./trunc'); | ||
|
||
it('should delegate implementation to alternate form', () => { | ||
const lhs = {} as Complex; | ||
const rhs = {} as Complex; | ||
const divLhsRhs = {} as Complex; | ||
const truncDivLhsRhs = {} as Complex; | ||
const mulTruncDivLhsRhsRhs = {} as Complex; | ||
const subLhsMulTruncDivLhsRhsRhs = {} as Complex; | ||
|
||
mock(div).mockReturnValueOnce(divLhsRhs); | ||
mock(trunc).mockReturnValueOnce(truncDivLhsRhs); | ||
mock(mul).mockReturnValueOnce(mulTruncDivLhsRhsRhs); | ||
mock(sub).mockReturnValueOnce(subLhsMulTruncDivLhsRhsRhs); | ||
|
||
const actual = sut(Complex, lhs, rhs); | ||
|
||
expect(div).toHaveBeenCalledWith(Complex, lhs, rhs); | ||
expect(trunc).toHaveBeenCalledWith(Complex, divLhsRhs); | ||
expect(mul).toHaveBeenCalledWith(Complex, truncDivLhsRhs, rhs); | ||
expect(sub).toHaveBeenCalledWith(Complex, lhs, mulTruncDivLhsRhsRhs); | ||
|
||
expect(actual).toBe(subLhsMulTruncDivLhsRhsRhs); | ||
}); |
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,9 @@ | ||
import Complex from '../complex'; | ||
import div from './div'; | ||
import mul from './mul'; | ||
import sub from './sub'; | ||
import trunc from './trunc'; | ||
|
||
export default (Ctor: typeof Complex, lhs: Complex, rhs: Complex): Complex => ( | ||
sub(Ctor, lhs, mul(Ctor, trunc(Ctor, div(Ctor, lhs, rhs)), rhs)) | ||
); |
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,30 @@ | ||
import _ from '../__fixtures__/any/number'; | ||
import mock from '../__fixtures__/mock'; | ||
|
||
import Complex from '../complex'; | ||
import Component from '../internal/component'; | ||
import { real, imag } from '../accessors'; | ||
import sut from './trunc'; | ||
|
||
jest.mock('../complex'); | ||
jest.mock('../accessors/real'); | ||
jest.mock('../accessors/imag'); | ||
|
||
it('should initialize polar components from cartesian components', () => { | ||
const testReal = 3.5; | ||
const testImag = -4.5; | ||
const z = new Complex(testReal, testImag, _, _, Component.CARTESIAN); | ||
const expected = {} as Complex; | ||
|
||
mock(Complex).mockClear(); | ||
mock(Complex).mockReturnValueOnce(expected); | ||
|
||
const actual = sut(Complex, z); | ||
|
||
expect(real).toHaveBeenCalledWith(Complex, z); | ||
expect(imag).toHaveBeenCalledWith(Complex, z); | ||
expect(Complex).toHaveBeenCalledWith( | ||
Math.trunc(testReal), Math.trunc(testImag), _, _, Component.CARTESIAN, | ||
); | ||
expect(actual).toBe(expected); | ||
}); |
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,9 @@ | ||
import Complex from '../complex'; | ||
import Component from '../internal/component'; | ||
import { real, imag } from '../accessors'; | ||
|
||
const trunc = (Ctor: typeof Complex, z: Complex): Complex => new Ctor( | ||
Math.trunc(real(Ctor, z)), Math.trunc(imag(Ctor, z)), 0, 0, Component.CARTESIAN, | ||
); | ||
|
||
export default trunc; |
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,21 @@ | ||
import mock from '../__fixtures__/mock'; | ||
|
||
import Complex from '../complex'; | ||
import mod from '../methods/mod'; | ||
import sut from './mod'; | ||
|
||
jest.mock('../complex'); | ||
jest.mock('../methods/mod'); | ||
|
||
it('should delegate to mod method', () => { | ||
const lhs = {} as Complex; | ||
const rhs = {} as Complex; | ||
const expected = {} as Complex; | ||
|
||
mock(mod).mockReturnValueOnce(expected); | ||
|
||
const actual = sut(lhs, rhs); | ||
|
||
expect(mod).toHaveBeenCalledWith(Complex, lhs, rhs); | ||
expect(actual).toBe(expected); | ||
}); |
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,6 @@ | ||
import Complex from '../complex'; | ||
import _mod from '../methods/mod'; | ||
|
||
const mod = (lhs: Complex, rhs: Complex): Complex => _mod(Complex, lhs, rhs); | ||
|
||
export default mod; |
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,20 @@ | ||
import mock from '../__fixtures__/mock'; | ||
|
||
import Complex from '../complex'; | ||
import trunc from '../methods/trunc'; | ||
import sut from './trunc'; | ||
|
||
jest.mock('../complex'); | ||
jest.mock('../methods/trunc'); | ||
|
||
it('should delegate to trunc method', () => { | ||
const z = {} as Complex; | ||
const expected = {} as Complex; | ||
|
||
mock(trunc).mockReturnValueOnce(expected); | ||
|
||
const actual = sut(z); | ||
|
||
expect(trunc).toHaveBeenCalledWith(Complex, z); | ||
expect(actual).toBe(expected); | ||
}); |
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,6 @@ | ||
import Complex from '../complex'; | ||
import _trunc from '../methods/trunc'; | ||
|
||
const trunc = (z: Complex): Complex => _trunc(Complex, z); | ||
|
||
export default trunc; |