-
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
Showing
1 changed file
with
74 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { PWMService, Polarity } from "../../src" | ||
import { PWMPin } from "../../src" | ||
|
||
jest.unmock('zeromq') | ||
|
||
describe('PwmService', () => { | ||
let pwm: PWMService | ||
|
||
beforeAll(async () => { | ||
pwm = new PWMService('tcp://localhost:5555'); | ||
await pwm.initPwm(PWMPin.PWM1) | ||
await pwm.initPwm(PWMPin.PWM2) | ||
}) | ||
|
||
test.each([ | ||
[{pwm_num: PWMPin.PWM1, polarity: Polarity.NORMAL}], | ||
[{pwm_num: PWMPin.PWM2, polarity: Polarity.INVERSED}], | ||
[{pwm_num: PWMPin.PWM1, frequency: 1000}], | ||
[{pwm_num: PWMPin.PWM1, duty_cycle: 0}] | ||
|
||
])('Call setConfig and check success message', async (args) => { | ||
const response = await pwm.setConfig(args) | ||
expect(response).toEqual('Successfully applied pwm configurations.') | ||
}) | ||
|
||
|
||
test.each([ | ||
[PWMPin.PWM1], | ||
[PWMPin.PWM2], | ||
])('Call enable and check success message', async (pwm_num) => { | ||
const response = await pwm.enable(pwm_num) | ||
expect(response).toEqual(`Successful enabled ${pwm_num}.`) | ||
}) | ||
|
||
test.each([ | ||
[PWMPin.PWM1], | ||
[PWMPin.PWM2], | ||
])('Call disable and check success message', async (pwm_num) => { | ||
const response = await pwm.disable(pwm_num) | ||
expect(response).toEqual(`Successful disabled ${pwm_num}.`) | ||
}) | ||
|
||
test.each([ | ||
[PWMPin.PWM1], | ||
[PWMPin.PWM2], | ||
])('Call close and check success message', async (pwm_num) => { | ||
const response = await pwm.close(pwm_num) | ||
expect(response).toEqual(`Successfully closed ${pwm_num}.`) | ||
}) | ||
|
||
test.each([ | ||
[PWMPin.PWM1], | ||
[PWMPin.PWM2], | ||
])('Call getFrequency and check frequency type', async (pwm_num) => { | ||
const frequency = await pwm.getFrequency(pwm_num) | ||
expect(typeof frequency).toBe('number') | ||
}) | ||
|
||
test.each([ | ||
[PWMPin.PWM1], | ||
[PWMPin.PWM2], | ||
])('Call getDutyCycle and duty cycle type', async (pwm_num) => { | ||
const dutyCycle = await pwm.getDutyCycle(pwm_num) | ||
expect(typeof dutyCycle).toBe('number') | ||
}) | ||
|
||
test.each([ | ||
[PWMPin.PWM1], | ||
[PWMPin.PWM2], | ||
])('Call getPolarity and check polarity type', async (pwm_num) => { | ||
const polarity = await pwm.getPolarity(pwm_num) | ||
expect(Object.values(Polarity)).toContain(polarity) | ||
}) | ||
}) |