How to resolve the algorithm Test a function step by step in the jq programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Test a function step by step in the jq programming language
Table of Contents
Problem Statement
Using a well-known testing-specific library/module/suite for your language, write some tests for your language's entry in Palindrome. If your language does not have a testing specific library well known to the language's community then state this or omit the language.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Test a function step by step in the jq programming language
Source code in the jq programming language
# Test case 1:
.
1
1
# Test case 2:
1+1
null
2
# Test case 3 (with the wrong result):
1+1
null
0
# A test case with a function definition:
def factorial: if . <= 0 then 1 else . * ((. - 1) | factorial) end; factorial
3
6
$ jq --run-tests < jq.tests
Testing '.' at line number 3
Testing '1+1' at line number 8
Testing '1+1' at line number 13
*** Expected 0, but got 2 for test at line number 15: 1+1
Testing 'def factorial: if . <= 0 then 1 else . * ((. - 1) | factorial) end; factorial' at line number 18
3 of 4 tests passed (0 malformed)
def factorial: if . <= 0 then 1 else . * ((. - 1) | factorial) end;
def palindrome: explode as $in | ($in|reverse) == $in;
import "library" as lib; lib::factorial
3
6
import "library" as lib; lib::palindrome
"salàlas"
true
jq --run-tests < test-library.txt
You may also check:How to resolve the algorithm Abbreviations, simple step by step in the Wren programming language
You may also check:How to resolve the algorithm Approximate equality step by step in the Python programming language
You may also check:How to resolve the algorithm Dot product step by step in the Oberon-2 programming language
You may also check:How to resolve the algorithm Sequence of non-squares step by step in the C++ programming language
You may also check:How to resolve the algorithm RPG attributes generator step by step in the 11l programming language