Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
9
Task/Test-a-function/EchoLisp/test-a-function.echolisp
Normal file
9
Task/Test-a-function/EchoLisp/test-a-function.echolisp
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
(assert (palindrome? "aba")) → #t
|
||||
(assert (palindrome? "abbbca") "palindrome fail")
|
||||
💥 error: palindrome fail : assertion failed : (palindrome? abbbca)
|
||||
|
||||
(check-expect (palindrome? "aba") #t) → #t
|
||||
(check-expect (palindrome? "abcda") #f) → #t
|
||||
(check-expect (palindrome? "abcda") #t)
|
||||
😐 warning: #t : check failed : (palindrome? abcda) → #f
|
||||
(assert (palindrome? "un roc lamina l animal cornu")) → #t
|
||||
37
Task/Test-a-function/Lasso/test-a-function.lasso
Normal file
37
Task/Test-a-function/Lasso/test-a-function.lasso
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
// Taken from the Lasso entry in Palindrome page
|
||||
define isPalindrome(text::string) => {
|
||||
|
||||
local(_text = string(#text)) // need to make copy to get rid of reference issues
|
||||
|
||||
#_text -> replace(regexp(`(?:$|\W)+`), -ignorecase)
|
||||
|
||||
local(reversed = string(#_text))
|
||||
#reversed -> reverse
|
||||
|
||||
return #_text == #reversed
|
||||
}
|
||||
|
||||
// The tests
|
||||
describe(::isPalindrome) => {
|
||||
it(`throws an error when not passed a string`) => {
|
||||
expect->error =>{
|
||||
isPalindrome(43)
|
||||
}
|
||||
}
|
||||
|
||||
it(`returns true if the string is the same forward and backwords`) => {
|
||||
expect(isPalindrome('abba'))
|
||||
}
|
||||
|
||||
it(`returns false if the string is different forward and backwords`) => {
|
||||
expect(not isPalindrome('aab'))
|
||||
}
|
||||
|
||||
it(`ignores spaces and punctuation`) => {
|
||||
expect(isPalindrome(`Madam, I'm Adam`))
|
||||
}
|
||||
}
|
||||
|
||||
// Run the tests and get the summary
|
||||
// (This normally isn't in the code as the test suite is run via command-line.)
|
||||
lspec->stop
|
||||
18
Task/Test-a-function/Nim/test-a-function-1.nim
Normal file
18
Task/Test-a-function/Nim/test-a-function-1.nim
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
proc reverse(s): string =
|
||||
result = newString(s.len)
|
||||
for i,c in s:
|
||||
result[s.high - i] = c
|
||||
|
||||
proc isPalindrome(s): bool =
|
||||
s == reverse(s)
|
||||
|
||||
when isMainModule:
|
||||
assert(isPalindrome(""))
|
||||
assert(isPalindrome("a"))
|
||||
assert(isPalindrome("aa"))
|
||||
assert(not isPalindrome("baa"))
|
||||
assert(isPalindrome("baab"))
|
||||
assert(isPalindrome("ba_ab"))
|
||||
assert(not isPalindrome("ba_ ab"))
|
||||
assert(isPalindrome("ba _ ab"))
|
||||
assert(not isPalindrome("abab"))
|
||||
26
Task/Test-a-function/Nim/test-a-function-2.nim
Normal file
26
Task/Test-a-function/Nim/test-a-function-2.nim
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import unittest
|
||||
|
||||
proc reverse(s): string =
|
||||
result = newString(s.len)
|
||||
for i,c in s:
|
||||
result[s.high - i] = c
|
||||
|
||||
proc isPalindrome(s): bool =
|
||||
s == reverse(s)
|
||||
|
||||
when isMainModule:
|
||||
suite "palindrome":
|
||||
test "empty string":
|
||||
check isPalindrome ""
|
||||
|
||||
test "string of length 1":
|
||||
check isPalindrome "a"
|
||||
|
||||
test "string of length 2":
|
||||
check isPalindrome "aa"
|
||||
|
||||
test "string of length 3":
|
||||
check isPalindrome "aaa"
|
||||
|
||||
test "no palindrome":
|
||||
check isPalindrome("foo") == false
|
||||
3
Task/Test-a-function/Oforth/test-a-function.oforth
Normal file
3
Task/Test-a-function/Oforth/test-a-function.oforth
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
test: [ "abcd" isPalindrome ]
|
||||
test: ["abba" isPalindrome ]
|
||||
test: [ "abcba" isPalindrome ]
|
||||
2
Task/Test-a-function/Ring/test-a-function.ring
Normal file
2
Task/Test-a-function/Ring/test-a-function.ring
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
assert(IsPalindrome("racecar"))
|
||||
assert(IsPalindrome("alice"))
|
||||
32
Task/Test-a-function/Swift/test-a-function.swift
Normal file
32
Task/Test-a-function/Swift/test-a-function.swift
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import Cocoa
|
||||
import XCTest
|
||||
|
||||
class PalindromTests: XCTestCase {
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
func testPalindrome() {
|
||||
// This is an example of a functional test case.
|
||||
XCTAssert(isPalindrome("abcba"), "Pass")
|
||||
XCTAssert(isPalindrome("aa"), "Pass")
|
||||
XCTAssert(isPalindrome("a"), "Pass")
|
||||
XCTAssert(isPalindrome(""), "Pass")
|
||||
XCTAssert(isPalindrome("ab"), "Pass") // Fail
|
||||
XCTAssert(isPalindrome("aa"), "Pass")
|
||||
XCTAssert(isPalindrome("abcdba"), "Pass") // Fail
|
||||
}
|
||||
|
||||
func testPalindromePerformance() {
|
||||
// This is an example of a performance test case.
|
||||
self.measureBlock() {
|
||||
var _is = isPalindrome("abcba")
|
||||
}
|
||||
}
|
||||
}
|
||||
19
Task/Test-a-function/jq/test-a-function-1.jq
Normal file
19
Task/Test-a-function/jq/test-a-function-1.jq
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# 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
|
||||
8
Task/Test-a-function/jq/test-a-function-2.jq
Normal file
8
Task/Test-a-function/jq/test-a-function-2.jq
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
$ 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)
|
||||
3
Task/Test-a-function/jq/test-a-function-3.jq
Normal file
3
Task/Test-a-function/jq/test-a-function-3.jq
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
def factorial: if . <= 0 then 1 else . * ((. - 1) | factorial) end;
|
||||
|
||||
def palindrome: explode as $in | ($in|reverse) == $in;
|
||||
7
Task/Test-a-function/jq/test-a-function-4.jq
Normal file
7
Task/Test-a-function/jq/test-a-function-4.jq
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import "library" as lib; lib::factorial
|
||||
3
|
||||
6
|
||||
|
||||
import "library" as lib; lib::palindrome
|
||||
"salàlas"
|
||||
true
|
||||
1
Task/Test-a-function/jq/test-a-function-5.jq
Normal file
1
Task/Test-a-function/jq/test-a-function-5.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
jq --run-tests < test-library.txt
|
||||
Loading…
Add table
Add a link
Reference in a new issue