Now the Test Cases can detect if you displayed the correct thing!
//// Created by RHB // Your code here const hello=()=>{ console.log("Hello, World!") }
## Created by RHB# Your code here[print(chr(i),end="") for i in [100, 108, 114, 111, 87, 32, 111, 108, 108, 101, 72][::-1]]- //// Created by RHB
- // Your code here
- const hello=()=>{
- console.log("Hello, World!")
- }
const {assert} = require("chai"); describe("Test Results", function() { it("does it print hello world", function() {s() // Run the user's function hello(); // Check if "Hello World" was logged const actual = consoleOutput.join('\n'); const expected = "Hello, World!";r() assert.equal(actual, expected); }); });
import codewars_test as test# TODO Write testsimport solution # or from solution import example- const {assert} = require("chai");
- describe("Test Results", function() {
- it("does it print hello world", function() {s()
# test.assert_equals(actual, expected, [optional] message)@test.describe("Test Results")def test_group():@test.it("does it print hello world")def test_case():test.expect(passed="Hello World", message=None, allow_raise=False)- // Run the user's function
- hello();
- // Check if "Hello World" was logged
- const actual = consoleOutput.join('\n');
- const expected = "Hello, World!";r()
- assert.equal(actual, expected);
- });
- });
Fundamentals
Strings
Add a given separator to a string at every n characters. When n is negative or equal to zero then return the orginal string.
but now in python
def insert_separator(seperator, after_every_x_chars, into_string): if after_every_x_chars <= 0: return into_string output = "" for index, c in enumerate(into_string): if index % after_every_x_chars == 0 and index > 0: output += seperator output += c return output
func insert(seperator: String, afterEveryXChars: Int, intoString: String) -> String {guard afterEveryXChars > 0 else { return intoString }var output = ""intoString.enumerated().forEach { index, c inif index % afterEveryXChars == 0 && index > 0 {- def insert_separator(seperator, after_every_x_chars, into_string):
- if after_every_x_chars <= 0:
- return into_string
- output = ""
- for index, c in enumerate(into_string):
- if index % after_every_x_chars == 0 and index > 0:
- output += seperator
}output.append(c)}- output += c
- return output
}
import codewars_test as test from solution import insert_separator @test.describe("Test Example") def testExample(): test.assert_equals(insert_separator('-', 0, "603555121"), "603555121") test.assert_equals(insert_separator('-', 1, "603555121"), "6-0-3-5-5-5-1-2-1") test.assert_equals(insert_separator('-', 3, "603555121"), "603-555-121") test.assert_equals(insert_separator('-', 4, "603555121"), "6035-5512-1") test.assert_equals(insert_separator('-', 5, "603555121"), "60355-5121") test.assert_equals(insert_separator('-', 10, "603555121"), "603555121")
import XCTest// XCTest Spec Example:// TODO: replace with your own tests (TDD), these are just how-to examples to get you started- import codewars_test as test
- from solution import insert_separator
class SolutionTest: XCTestCase {static var allTests = [("Test Example", testExample),]func testExample() {XCTAssertEqual(insert(seperator: "-", afterEveryXChars: 0, intoString: "603555121"), "603555121")XCTAssertEqual(insert(seperator: "-", afterEveryXChars: 1, intoString: "603555121"), "6-0-3-5-5-5-1-2-1")XCTAssertEqual(insert(seperator: "-", afterEveryXChars: 3, intoString: "603555121"), "603-555-121")XCTAssertEqual(insert(seperator: "-", afterEveryXChars: 4, intoString: "603555121"), "6035-5512-1")XCTAssertEqual(insert(seperator: "-", afterEveryXChars: 5, intoString: "603555121"), "60355-5121")XCTAssertEqual(insert(seperator: "-", afterEveryXChars: 10, intoString: "603555121"), "603555121")}}XCTMain([testCase(SolutionTest.allTests)])- @test.describe("Test Example")
- def testExample():
- test.assert_equals(insert_separator('-', 0, "603555121"), "603555121")
- test.assert_equals(insert_separator('-', 1, "603555121"), "6-0-3-5-5-5-1-2-1")
- test.assert_equals(insert_separator('-', 3, "603555121"), "603-555-121")
- test.assert_equals(insert_separator('-', 4, "603555121"), "6035-5512-1")
- test.assert_equals(insert_separator('-', 5, "603555121"), "60355-5121")
- test.assert_equals(insert_separator('-', 10, "603555121"), "603555121")
Fundamentals
Strings
short and simple