def solution():
import tests
tests.refsol()
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
def refsol():
print('I am refsol')
@test.it('test')
def _():
solution.solution()
test.pass_()
table | table |
---|---|
table | formatting |
is | supported |
console.log('table!')
// Since Node 10, we're using Mocha.
// You can use `chai` for assertions.
const chai = require("chai");
const assert = chai.assert;
// Uncomment the following line to disable truncating failure messages for deep equals, do:
// chai.config.truncateThreshold = 0;
// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
// Uncomment the following to use the old assertions:
// const Test = require("@codewars/test-compat");
describe("Solution", function() {
it("should test for something", function() {
// Test.assertEquals(1 + 1, 2);
// assert.strictEqual(1 + 1, 2);
});
});
import socket
import time
def socket_client():
print('b')
a = socket.socket()
time.sleep(0.1)
a.connect(('127.0.0.1',1111))
a.send("1234".encode())
result = a.recv(1024).decode()
a.close()
return result == "1234"
import codewars_test as test
from solution import socket_client
import socket
import random
import threading
import time
class result_thread(threading.Thread):
def __init__(self,target = None, **kargs):
def set_result():
self.result = target()
super().__init__(target = set_result, **kargs)
def socket_server_regular():
print('a')
a = socket.socket()
a.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
a.bind(('127.0.0.1',1111))
a.listen()
con, ip = a.accept()
ans = con.recv(1024).decode()
con.send(ans.encode())
a.close()
con.close()
def socket_server_reversed():
print('aa')
a = socket.socket()
a.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
a.bind(('127.0.0.1',1111))
a.listen()
con, ip = a.accept()
ans = con.recv(1024).decode()
con.send(''.join(reversed(ans)).encode())
a.close()
con.close()
def random_tests():
for i in range(5):
server = random.choice([True,False])
server_thread = result_thread(target = socket_server_regular if server else socket_server_reversed)
client_thread = result_thread(target = socket_client)
server_thread.start()
client_thread.start()
server_thread.join()
client_thread.join()
test.expect(client_thread.result == server)
time.sleep(0.1)
random_tests()
Doesn't work on Codewars as of writing :(
Now it works!
.section .text
.global rvv_memcpy
rvv_memcpy:
1:
vsetvli a3, a2, e8, m8, ta, ma
vle8.v v8, (a1)
vse8.v v8, (a0)
add a0, a0, a3
add a1, a1, a3
sub a2, a2, a3
bnez a2, 1b
ret
// Tests for RISC-V are written in C with Cgreen.
// See <https://cgreen-devs.github.io/cgreen/cgreen-guide-en.html>.
#include <cgreen/cgreen.h>
#include <stdlib.h>
#include <time.h>
#include <stddef.h>
void rvv_memcpy(void *dst, const void *src, size_t len);
// `Describe`, `BeforeEach`, and `AfterEach` are required.
Describe(rvv_memcpy);
BeforeEach(rvv_memcpy) {}
AfterEach(rvv_memcpy) {}
Ensure(rvv_memcpy, works_for_fixed_tests) {
char src[] = "Hello, world!";
char dst[] = "Aloha, RISC-V vectors!";
rvv_memcpy(dst, src, 5);
assert_that(dst, is_equal_to_string("Hello, RISC-V vectors!"));
}
// `solution_tests` to create a test suite is required.
TestSuite *solution_tests() {
TestSuite *suite = create_test_suite();
add_test_with_context(suite, rvv_memcpy, works_for_fixed_tests);
return suite;
}
.section .text
.global solution
solution:
la a0, msg
tail preloaded_function
.section .rodata
msg:
.string "butterfly"
// Tests for RISC-V are written in C with Cgreen.
// See <https://cgreen-devs.github.io/cgreen/cgreen-guide-en.html>.
#include <cgreen/cgreen.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <stddef.h>
void preloaded_function(const char *animal) {
printf("*points at %s* is this preloaded code?", animal);
}
void solution(void);
// `Describe`, `BeforeEach`, and `AfterEach` are required.
Describe(Example);
BeforeEach(Example) {}
AfterEach(Example) {}
Ensure(Example, test) {
solution();
}
// `solution_tests` to create a test suite is required.
TestSuite *solution_tests() {
TestSuite *suite = create_test_suite();
add_test_with_context(suite, Example, test);
return suite;
}