2020-04-06 11:17:22 +00:00
|
|
|
'use strict'
|
2019-05-04 16:08:30 +00:00
|
|
|
|
2020-04-06 11:17:22 +00:00
|
|
|
// Every test file (you can create as many as you want) should start like this
|
|
|
|
// Please, do NOT touch. They will be automatically removed for browser tests -->
|
|
|
|
const _pkg = require('../lib/index.node')
|
|
|
|
const chai = require('chai')
|
|
|
|
// <--
|
2019-05-04 16:08:30 +00:00
|
|
|
|
|
|
|
const inputs = [
|
2020-04-06 11:17:22 +00:00
|
|
|
{
|
|
|
|
a: BigInt(1),
|
|
|
|
b: BigInt(1),
|
|
|
|
gcd: BigInt(1)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: BigInt(0),
|
|
|
|
b: BigInt(189),
|
|
|
|
gcd: BigInt(189)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: BigInt(189),
|
|
|
|
b: BigInt(0),
|
|
|
|
gcd: BigInt(189)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: BigInt(0),
|
|
|
|
b: BigInt(0),
|
|
|
|
gcd: BigInt(0)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: BigInt(1),
|
|
|
|
b: BigInt('14546149867129487614601346814'),
|
|
|
|
gcd: BigInt(1)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: BigInt(27),
|
|
|
|
b: BigInt(18),
|
|
|
|
gcd: BigInt(9)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: BigInt(-27),
|
|
|
|
b: BigInt(18),
|
|
|
|
gcd: BigInt(9)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109'),
|
|
|
|
b: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109') * BigInt('144678545212641449725111562354371812236197961234111744040227045242578772124779004756249085154188369039159690638725821245974978963371615699005072473649705367893567309027634121825164880046600125480885803891136149601797439273507802533807541605261215613891134865916295914192271736572001975016089773532547481638243'),
|
|
|
|
gcd: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109')
|
|
|
|
}
|
|
|
|
]
|
2019-05-04 16:08:30 +00:00
|
|
|
|
|
|
|
describe('gcd', function () {
|
2020-04-06 11:17:22 +00:00
|
|
|
for (const input of inputs) {
|
|
|
|
describe(`gcd(${input.a}, ${input.b})`, function () {
|
|
|
|
it(`should return ${input.gcd}`, function () {
|
|
|
|
const ret = _pkg.gcd(input.a, input.b)
|
|
|
|
chai.expect(ret).to.equal(input.gcd)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|