awan_world=lambda _:f"{['Goodbye','awan'][_]}, World"
hello_world=lambda _:f"{['Goodbye','Hello'][_]}, World"- awan_world=lambda _:f"{['Goodbye','awan'][_]}, World"
import codewars_test as test # TODO Write tests import solution # or from solution import example # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(awan_world(True), "awan, World") test.assert_equals(awan_world(False), "Goodbye, World")
- import codewars_test as test
- # TODO Write tests
- import solution # or from solution import example
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
test.assert_equals(hello_world(True), "Hello, World")test.assert_equals(hello_world(False), "Goodbye, World")- test.assert_equals(awan_world(True), "awan, World")
- test.assert_equals(awan_world(False), "Goodbye, World")
function rps(player1, player2) { if (player1 === player2) { return 'Draw!'; } else if ( (player1 === 'rock' && player2 === 'scissors') || (player1 === 'scissors' && player2 === 'paper') || (player1 === 'paper' && player2 === 'rock') ) { return 'Player 1 won!'; } else {pp return 'Player 2 won!'; } }
- function rps(player1, player2) {
- if (player1 === player2) {
- return 'Draw!';
- } else if (
- (player1 === 'rock' && player2 === 'scissors') ||
- (player1 === 'scissors' && player2 === 'paper') ||
- (player1 === 'paper' && player2 === 'rock')
- ) {
- return 'Player 1 won!';
} else {- } else {pp
- return 'Player 2 won!';
- }
- }
// Create a canvas element
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
document.body.appendChild(canvas);
// Set canvas size
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
// Car object
const car = {
x: 50,
y: canvas.height / 2,
width: 100,
height: 50,
speed: 5,
draw: function() {
ctx.fillStyle = 'blue';
ctx.fillRect(this.x, this.y, this.width, this.height);
},
update: function() {
this.x += this.speed;
if (this.x > canvas.width) {
this.x = -this.width;
}
}
};
// Animation loop
function animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
car.draw();
car.update();
requestAnimationFrame(animate);
}
// Start the animation
animate();
// Since Node 10, we're using Mocha.
// You can use `chai` for assertions.
const canvas = require("canvas");
const ctx = canvas.ctx;
// 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("animate"0) {
it("should test for something", function("animate") {
// Test.assertEquals(1 + 1, 2);
// assert.strictEqual(1 + 1, 2);
});
});
// Create a canvas element
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
document.body.appendChild(canvas);
// Set canvas size
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
// Car object
const car = {
x: 50,
y: canvas.height / 2,
width: 100,
height: 50,
speed: 5,
draw: function() {
ctx.fillStyle = 'blue';
ctx.fillRect(this.x, this.y, this.width, this.height);
},
update: function() {
this.x += this.speed;
if (this.x > canvas.width) {
this.x = -this.width;
}
}
};
// Animation loop
function animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
car.draw();
car.update();
requestAnimationFrame(animate);
}
// Start the animation
animate();