Error displaying in prolog.
add(A, B, R) :- number(A) , number(B) , R is A + B +2 %wrong part to show formatting tricks .
add(A, B, R) :- R is A + B.- add(A, B, R) :-
- number(A)
- , number(B)
- , R is A + B
- +2 %wrong part to show formatting tricks
- .
:- begin_tests(kata). :- include(kata). :- use_module(library(writef)). test(basic_tests) :- add(3, 5, X), ((X == 8) -> nl;writeln('<FAILED::>3+5 should be 8')), assertion(X == 8). test(basic_tests) :- add(1, 2, X), assertion(X == 3), ((X == 3) -> nl;writeln('<FAILED::>1+2 should be 3')). test(basic_tests) :- add(1, 5, X), assertion(X == 6), ((X == 6) -> nl;writeln('<FAILED::>1+5 should be 6')). sol(A, B, R) :- R is A + B. test(random_tests, [forall(between(1, 100, _))]) :- random(1, 20, A), random(1, 20, B), add(A, B, X), sol(A, B, R), assertion(X == R), ((X == R) -> nl;writef('<FAILED::>%d + %d should be %d not %d',[A,B,R,X]),nl,nl) . :- end_tests(kata).
- :- begin_tests(kata).
- :- include(kata).
- :- use_module(library(writef)).
test(basic_tests) :- add(3, 5, X), assertion(X == 8).test(basic_tests) :- add(1, 2, X), assertion(X == 3).test(basic_tests) :- add(1, 5, X), assertion(X == 6).- test(basic_tests) :- add(3, 5, X), ((X == 8) -> nl;writeln('<FAILED::>3+5 should be 8')), assertion(X == 8).
- test(basic_tests) :- add(1, 2, X), assertion(X == 3), ((X == 3) -> nl;writeln('<FAILED::>1+2 should be 3')).
- test(basic_tests) :- add(1, 5, X), assertion(X == 6), ((X == 6) -> nl;writeln('<FAILED::>1+5 should be 6')).
- sol(A, B, R) :- R is A + B.
- test(random_tests, [forall(between(1, 100, _))]) :-
- random(1, 20, A),
- random(1, 20, B),
- add(A, B, X),
- sol(A, B, R),
assertion(X == R).- assertion(X == R),
- ((X == R) -> nl;writef('<FAILED::>%d + %d should be %d not %d',[A,B,R,X]),nl,nl)
- .
- :- end_tests(kata).
This Kumite is created to test JQuery support on Codewars.
var jsdom = require("jsdom/lib/old-api.js");
jsdom.env(
'<!DOCTYPE html><p>Hello world</p><a class="the-link" href="https://github.com/tmpvar/jsdom">jsdom!</a>', ["http://code.jquery.com/jquery.js"],
function(err, window) {
console.log(window.document.querySelector("p").textContent);
var $ = window.$;
$.getJSON('https://www.codewars.com/users/Javatlacati', null, function(data) {
console.log(data);
}).error(function(e) {
console.log("first attempt failed\n" + JSON.stringify(e));
});
var name = "kazk";
var url = "http://anyorigin.com/go?url=" + encodeURIComponent("https://www.codewars.com/users/") + name + "&callback=?";
$.get(url, function(response) {
console.log(response);
}).error(function(e) {
console.log("second attempt failed\n" + JSON.stringify(e));
});
console.log("contents of a.the-link:", window.$("a.the-link").text());
}
);
Do you know where you are?
You had a massive hangover and don't rememeber where are you.
Use your system to know info about your enviroment.
SQL
Retrieve the current database
SELECT current_database();
results = run_sql
describe :apisjd do
it "should return 1 element" do
expect(results.count).to eq 1
end
end
// add the values "codewars" to the websites array
var websites = ['codears'];
test('Codewars is in the array', () {
expect(websites.length, greaterThan(0));
expect(websites.length, equals(1));
expect(websites[0], equals('codewars'),reason:"codewars website should be present in the array", verbose:true);
});
That's a simple threading test using JavaFX. It currently has troubles due to codewars JVM runner.
import java.util.concurrent.atomic.AtomicInteger;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.stage.Stage;
/** Created by Javatlacati on 08/02/2017. */
public class Aciago extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
Thread miHilo =
new Thread(
new Runnable() {
final AtomicInteger i = new AtomicInteger(0);
@Override
public void run() {
System.out.println("Corriendo");
while (true) {
Platform.runLater(
new Runnable() {
@Override
public void run() {
System.out.println(i.getAndIncrement() + " ola soi un hilo :v");
}
});
try {
if (i.get() < 4) {
System.out.println("anuma me voi a dormir");
Thread.sleep(1000);
} else {
throw new InterruptedException("#PosMeMuero");
}
} catch (InterruptedException ex) {
System.err.println("#ToyMorido");
Platform.exit();
System.out.println("JavaFx is dead");
break;
}
}
}
});
miHilo.setName("soy el mapa soy el mapa soy el mapa soy el mapa soy el mapa!");
miHilo.setDaemon(false);
miHilo.start();
}
}
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
// TODO: Replace examples and use TDD development by writing your own tests
public class SolutionTest {
@Test
public void testSomething() {
Aciago.main(null);
}
}
Any help is welcome :)
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* Created by Javatlacati on 07/02/2017.
*/
public class ThreadIssueSolution extends ScheduledThreadPoolExecutor {
public boolean isUsable=true;
public ThreadIssueSolution() {
super(1);
}
@Override
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
return super.scheduleAtFixedRate(wrapRunnable(command), initialDelay, period, unit);
}
@Override
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
return super.scheduleWithFixedDelay(wrapRunnable(command), initialDelay, delay, unit);
}
private Runnable wrapRunnable(Runnable command) {
return new LogOnExceptionRunnable(command);
}
@Override
protected void afterExecute(Runnable r, Throwable t) {
// super.afterExecute(r, t);
if(!(t == null && r == null)){
throw new ArithmeticException("ooops");
}
}
private class LogOnExceptionRunnable implements Runnable {
private Runnable theRunnable;
public LogOnExceptionRunnable(Runnable theRunnable) {
super();
this.theRunnable = theRunnable;
}
@Override
public void run() {
try {
theRunnable.run();
} catch (Throwable e) {
System.err.println("error ejecutando: " + theRunnable + ". no seguirá corriendo!");
//e.printStackTrace();
// and re throw it so that the Executor also gets this error so that it can do what it would
// usually do
throw new RuntimeException(e);
}
}
}
}
import org.junit.Test;
import java.util.concurrent.*;
/**
* Created by Javatlacati on 07/02/2017.
*/
public class PoolThreadIssueKataTest {
@Test(expected = RuntimeException.class)
public void testThread() throws ExecutionException{
ThreadIssueSolution issueSolution = new ThreadIssueSolution();
ScheduledFuture task;
if( issueSolution.isUsable){
task=issueSolution.scheduleAtFixedRate(new PoolThreadIssueKata(), 1, 1, TimeUnit.SECONDS);
}else{
task=Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(new PoolThreadIssueKata(), 1, 1, TimeUnit.SECONDS);
}
try {
Thread.sleep(302);
} catch (InterruptedException e) {
System.out.println("Interrupted");
}
try {
Object result = task.get(); //302,TimeUnit.MILLISECONDS
System.out.println(result);
} catch (InterruptedException e) {
System.out.println("interrupoted result");
}
// catch (TimeoutException e) {
// e.printStackTrace();
// }
// task.cancel(false);
// issueSolution.shutdown();
System.out.println("Test ended");
}
}
Shows how to use bash kta and how to create simple tests
echo Hello Bash!
# TODO: replace with your own tests (TDD). An example to get you started is included below.
# run the solution and store its result
output = run_shell
describe "Solution" do
it "should return the argument passed in" do
expect(output).to include('Hello Bash!')
end
end
Kotlin Hello World modified to show some language features
/**
* Created by Javatlacati on 26/10/2016.
*/
object LambdaKotlin {
@JvmStatic
fun main(args: Array<String>) {
val arr=arrayOf("hola","mundo","cruel")
arr.forEach {
println(it)
}
}
}
#include <string> #include <stdio.h> int Main() { int arg1, arg2, add, sub, mul, quo, rem ; printf( "Enter two integer numbers : " ); scanf( "%d%d", &arg1, &arg2 ); //no scanf provided hope to get memory garbage as number /* Perform Addition, Subtraction, Multiplication & Division */ __asm__ ( "addl %%ebx, %%eax;" : "=a" (add) : "a" (arg1) , "b" (arg2) ); __asm__ ( "subl %%ebx, %%eax;" : "=a" (sub) : "a" (arg1) , "b" (arg2) ); __asm__ ( "imull %%ebx, %%eax;" : "=a" (mul) : "a" (arg1) , "b" (arg2) ); __asm__ ( "movl $0x0, %%edx;" "movl %2, %%eax;" "movl %3, %%ebx;" "idivl %%ebx;" : "=a" (quo), "=d" (rem) : "g" (arg1), "g" (arg2) ); printf( "%d + %d = %d\n", arg1, arg2, add ); printf( "%d - %d = %d\n", arg1, arg2, sub ); printf( "%d * %d = %d\n", arg1, arg2, mul ); printf( "%d / %d = %d\n", arg1, arg2, quo ); printf( "%d %% %d = %d\n", arg1, arg2, rem ); return 0 ; }
int main(){printf("%d\n", test());}- #include <string>
- #include <stdio.h>
int test()- int Main()
- {
__asm__("movl $1337, %eax");- int arg1, arg2, add, sub, mul, quo, rem ;
- printf( "Enter two integer numbers : " );
- scanf( "%d%d", &arg1, &arg2 ); //no scanf provided hope to get memory garbage as number
- /* Perform Addition, Subtraction, Multiplication & Division */
- __asm__ ( "addl %%ebx, %%eax;" : "=a" (add) : "a" (arg1) , "b" (arg2) );
- __asm__ ( "subl %%ebx, %%eax;" : "=a" (sub) : "a" (arg1) , "b" (arg2) );
- __asm__ ( "imull %%ebx, %%eax;" : "=a" (mul) : "a" (arg1) , "b" (arg2) );
- __asm__ ( "movl $0x0, %%edx;"
- "movl %2, %%eax;"
- "movl %3, %%ebx;"
- "idivl %%ebx;" : "=a" (quo), "=d" (rem) : "g" (arg1), "g" (arg2) );
- printf( "%d + %d = %d\n", arg1, arg2, add );
- printf( "%d - %d = %d\n", arg1, arg2, sub );
- printf( "%d * %d = %d\n", arg1, arg2, mul );
- printf( "%d / %d = %d\n", arg1, arg2, quo );
- printf( "%d %% %d = %d\n", arg1, arg2, rem );
- return 0 ;
- }
// TODO: TDD development by writing your own tests as you solve the kata Describe(any_group_name_you_want) { It(should_do_something) { Assert::That(Main(), Equals(0)); } };
- // TODO: TDD development by writing your own tests as you solve the kata
- Describe(any_group_name_you_want)
- {
- It(should_do_something)
- {
- Assert::That(Main(), Equals(0));
- }
- };
Easy sample of how to run a hello world and use basic test.
#include <iostream> #include <string> int helloCplusplus(){ std::string str = "Hello, C++!"; std::cout << str << '\n'; return 0; }
System.Console.WriteLine("Hello, C#!");- #include <iostream>
- #include <string>
- int helloCplusplus(){
- std::string str = "Hello, C++!";
- std::cout << str << '\n';
- return 0;
- }
// TODO: TDD development by writing your own tests as you solve the kata Describe(Group_C_plus_plus) { It(test_proper_exit) { Assert::That(helloCplusplus(), Equals(0)); } };
- // TODO: TDD development by writing your own tests as you solve the kata
- Describe(Group_C_plus_plus)
- {
- It(test_proper_exit)
- {
- Assert::That(helloCplusplus(), Equals(0));
- }
- };
Code from the official page
class MyTestCase extends GroovyTestCase {
void testAssertions() {
assertTrue(1 == 1)
assertEquals("test", "test")
def x = "42"
assertNotNull "x must not be null", x
assertNull null
assertSame x, x
}
}
defmodule Solution do def sum(a, b) do a + b end end
sum = fn a, b -> a + b end- defmodule Solution do
- def sum(a, b) do
- a + b
- end
- end
defmodule TestSolution do use ExUnit.Case test "some test description" do assert Solution.sum(2,3) == 5 end end
# Create your own tests here. ExUnit is supported.- defmodule TestSolution do
- use ExUnit.Case
- test "some test description" do
assert sum(2,3) == 5- assert Solution.sum(2,3) == 5
- end
- end
# Create your own tests here. ExUnit is supported. defmodule TestSolution do use ExUnit.Case test "some test description" do assert sum(2,3) == 5 end end
- # Create your own tests here. ExUnit is supported.
- defmodule TestSolution do
- use ExUnit.Case
- test "some test description" do
- assert sum(2,3) == 5
- end
- end