1
1
Fork 0
exercism/jq/prime-factors/test-prime-factors.bats
Christina Sørensen 7f8baa2d63
feat(jq): prime-factor
Signed-off-by: Christina Sørensen <christina@cafkafk.com>
2024-12-18 17:21:15 +01:00

172 lines
2.7 KiB
Bash

#!/usr/bin/env bats
# generated on 2024-07-12T18:41:13Z
load bats-extra
load bats-jq
@test 'no factors' {
#
run jq -c -f prime-factors.jq << 'END_INPUT'
{
"value": 1
}
END_INPUT
assert_success
expected='[]'
assert_equal "$output" "$expected"
}
@test 'prime number' {
run jq -c -f prime-factors.jq << 'END_INPUT'
{
"value": 2
}
END_INPUT
assert_success
expected='[2]'
assert_equal "$output" "$expected"
}
@test 'another prime number' {
run jq -c -f prime-factors.jq << 'END_INPUT'
{
"value": 3
}
END_INPUT
assert_success
expected='[3]'
assert_equal "$output" "$expected"
}
@test 'square of a prime' {
run jq -c -f prime-factors.jq << 'END_INPUT'
{
"value": 9
}
END_INPUT
assert_success
expected='[3,3]'
assert_equal "$output" "$expected"
}
@test 'product of first prime' {
run jq -c -f prime-factors.jq << 'END_INPUT'
{
"value": 4
}
END_INPUT
assert_success
expected='[2,2]'
assert_equal "$output" "$expected"
}
@test 'cube of a prime' {
run jq -c -f prime-factors.jq << 'END_INPUT'
{
"value": 8
}
END_INPUT
assert_success
expected='[2,2,2]'
assert_equal "$output" "$expected"
}
@test 'product of second prime' {
run jq -c -f prime-factors.jq << 'END_INPUT'
{
"value": 27
}
END_INPUT
assert_success
expected='[3,3,3]'
assert_equal "$output" "$expected"
}
@test 'product of third prime' {
run jq -c -f prime-factors.jq << 'END_INPUT'
{
"value": 625
}
END_INPUT
assert_success
expected='[5,5,5,5]'
assert_equal "$output" "$expected"
}
@test 'product of first and second prime' {
run jq -c -f prime-factors.jq << 'END_INPUT'
{
"value": 6
}
END_INPUT
assert_success
expected='[2,3]'
assert_equal "$output" "$expected"
}
@test 'product of primes and non-primes' {
run jq -c -f prime-factors.jq << 'END_INPUT'
{
"value": 12
}
END_INPUT
assert_success
expected='[2,2,3]'
assert_equal "$output" "$expected"
}
@test 'product of primes' {
run jq -c -f prime-factors.jq << 'END_INPUT'
{
"value": 901255
}
END_INPUT
assert_success
expected='[5,17,23,461]'
assert_equal "$output" "$expected"
}
@test 'factors include a large prime' {
run jq -c -f prime-factors.jq << 'END_INPUT'
{
"value": 93819012551
}
END_INPUT
assert_success
expected='[11,9539,894119]'
assert_equal "$output" "$expected"
}