Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View 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

View 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

View 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"))

View 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

View file

@ -0,0 +1,3 @@
test: [ "abcd" isPalindrome ]
test: ["abba" isPalindrome ]
test: [ "abcba" isPalindrome ]

View file

@ -0,0 +1,2 @@
assert(IsPalindrome("racecar"))
assert(IsPalindrome("alice"))

View 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")
}
}
}

View 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

View 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)

View file

@ -0,0 +1,3 @@
def factorial: if . <= 0 then 1 else . * ((. - 1) | factorial) end;
def palindrome: explode as $in | ($in|reverse) == $in;

View file

@ -0,0 +1,7 @@
import "library" as lib; lib::factorial
3
6
import "library" as lib; lib::palindrome
"salàlas"
true

View file

@ -0,0 +1 @@
jq --run-tests < test-library.txt