Kumite (ko͞omiˌtā) is the practice of taking techniques learned from Kata and applying them through the act of freestyle sparring.
You can create a new kumite by providing some initial code and optionally some test cases. From there other warriors can spar with you, by enhancing, refactoring and translating your code. There is no limit to how many warriors you can spar with.
A great use for kumite is to begin an idea for a kata as one. You can collaborate with other code warriors until you have it right, then you can convert it to a kata.
pub struct Person { pub first_name: String, pub last_name: String } impl Person { pub fn new(first_name: String, last_name: String) -> Self { Self { first_name, last_name } } pub fn full_name(&self) -> String { format!("{} {}", self.first_name, self.last_name) } }
class Person {String firstName;String lastName;Person(this.firstName,this.lastName);- pub struct Person {
- pub first_name: String,
- pub last_name: String
- }
- impl Person {
- pub fn new(first_name: String, last_name: String) -> Self {
- Self { first_name, last_name }
- }
- pub fn full_name(&self) -> String {
- format!("{} {}", self.first_name, self.last_name)
- }
- }
#[cfg(test)] mod tests { use super::*; #[test] fn test_create() { let _: Person = Person::new("Bill".into(), "Smith".into()); } #[test] fn test_names() { let p = Person::new("Bill".into(), "Smith".into()); assert_eq!(p.first_name, "Bill"); assert_eq!(p.last_name, "Smith"); } #[test] fn test_full_name() { let p = Person::new("Bill".into(), "Smith".into()); assert_eq!(p.full_name(), "Bill Smith"); } }
// Create your own tests here using the Test package (https://github.com/dart-lang/test)// Here is some boilerplate:test('Should be able to create a Person object', () {expect(new Person('Bill', 'Smith'), new isInstanceOf<Person>());});test('Person object has expected name', () {var p = new Person('Bill', 'Smith');expect(p.firstName, equals('Bill'));expect(p.lastName, equals('Smith'));});- #[cfg(test)]
- mod tests {
- use super::*;
- #[test]
- fn test_create() {
- let _: Person = Person::new("Bill".into(), "Smith".into());
- }
- #[test]
- fn test_names() {
- let p = Person::new("Bill".into(), "Smith".into());
- assert_eq!(p.first_name, "Bill");
- assert_eq!(p.last_name, "Smith");
- }
- #[test]
- fn test_full_name() {
- let p = Person::new("Bill".into(), "Smith".into());
- assert_eq!(p.full_name(), "Bill Smith");
- }
- }
fn pekora<T, U>(_: T, _: U) -> &'static str { "candy" } fn add<T>(_: T) -> &'static str { "candy" }
pekora(a,b)=> 'candy';add(a)=> 'candy';- fn pekora<T, U>(_: T, _: U) -> &'static str {
- "candy"
- }
- fn add<T>(_: T) -> &'static str {
- "candy"
- }
#[test] fn test() { assert_eq!(pekora(1, 1), "candy"); assert_eq!(add(11), "candy"); }
// See https://pub.dartlang.org/packages/testimport "package:test/test.dart";import "package:solution/solution.dart";void main() {test("aaa", () {expect(pekora(1, 1), equals('candy'));expect(add(11), equals('candy'));});- #[test]
- fn test() {
- assert_eq!(pekora(1, 1), "candy");
- assert_eq!(add(11), "candy");
- }
O(n) solution
use std::collections::BTreeSet; fn string_editor(s: &str) -> String { let mut present = BTreeSet::new(); let mut doubled = BTreeSet::new(); for c in s.chars() { if present.contains(&c) { doubled.insert(c); } else { present.insert(c); } } s.chars().filter(|c| doubled.contains(c)).collect() }
#include <stdlib.h>#include <stdio.h>#include <string.h>- use std::collections::BTreeSet;
char* string_editor(char* str){char temp = 0;char size = (char)strlen(str);char *new = (char*)calloc(size,sizeof(char));for (char i = 0; i < size; i++)for (char j = 0; j < size; j++)if ((str[i] == str[j]) && (i != j))new[temp++] = str[i];new[temp] ='\0';return new;- fn string_editor(s: &str) -> String {
- let mut present = BTreeSet::new();
- let mut doubled = BTreeSet::new();
- for c in s.chars() {
- if present.contains(&c) {
- doubled.insert(c);
- } else {
- present.insert(c);
- }
- }
- s.chars().filter(|c| doubled.contains(c)).collect()
- }
#[test] fn test() { assert_eq!(string_editor("cac"), "cc"); assert_eq!(string_editor("ekekua"), "ekek"); assert_eq!(string_editor("aabcc"), "aacc"); assert_eq!(string_editor("aaabbbg"), "aaabbb"); assert_eq!(string_editor("pppenm"), "ppp"); }
#include <criterion/criterion.h>char* string_editor( char* str );Test(string_editor, is_example_case_1){char* actual0 = string_editor("accenture");char* expected0 = "ccee";cr_assert_str_eq(actual0, expected0);};Test(string_editor, is_example_case_2){char* actual0 = string_editor("testengineer");char* expected0 = "eeee";cr_assert_str_eq(actual0, expected0);};- #[test]
- fn test() {
- assert_eq!(string_editor("cac"), "cc");
- assert_eq!(string_editor("ekekua"), "ekek");
- assert_eq!(string_editor("aabcc"), "aacc");
- assert_eq!(string_editor("aaabbbg"), "aaabbb");
- assert_eq!(string_editor("pppenm"), "ppp");
- }
mod preloaded; use preloaded::Instruction; use std::iter::{once, repeat}; fn string_to_brainf(s: &str) -> Vec<Instruction> { s.chars() .flat_map(|c| { once(Instruction::Right) .chain(repeat(Instruction::Increment).take(c as usize)) .chain(once(Instruction::Output)) }) .collect() }
#include <stdio.h>#include <string.h>// #define DEBUG- mod preloaded;
- use preloaded::Instruction;
char s[4096] = "";int s2b(int argc, char *argv[]) {register int i = 0,j;register int k,m;register int l,last = 0;if (argc != 2) {printf("Usage: %s [string]",*argv);return 1;}while (argv[1][++i]!=0)continue;for (j=0; j<i; j++) {register int t;t = argv[1][j];l = k = t-last;last = t;#ifdef DEBUGprintf("\n%d, %d, %d, %d\n",last,k,j,i);#endif- use std::iter::{once, repeat};
if (k >= 0) {k >>= 3; // k /= 8l &= 7; //在更多的机器工作,求余if (k == 1)strcat(s,">++++++++");else {if (k != 0) {strcat(s,"++++++++[>");for (m=0; m<k; m++)strcat(s,"+");strcat(s,"<-]>");} else {strcat(s,">");}}for (m=0; m<l; m++)strcat(s,"+");strcat(s,".");} else {k = -k >> 3; // k /= 8l = -l & 7; //在更多的机器工作,求余if (k == 1)strcat(s,">--------");else {strcat(s,"++++++++[>");for (m=0; m<k; m++)strcat(s,"-");strcat(s,"<-]>");}for (m=0; m<l; m++)strcat(s,"-");strcat(s,".");}#ifdef DEBUGprintf("\n%d, %d, %d\n",m,k,l);#endifstrcat(s,"<");}return 0;- fn string_to_brainf(s: &str) -> Vec<Instruction> {
- s.chars()
- .flat_map(|c| {
- once(Instruction::Right)
- .chain(repeat(Instruction::Increment).take(c as usize))
- .chain(once(Instruction::Output))
- })
- .collect()
- }
#[cfg(test)] mod tests { use super::*; #[test] fn test() { test_string("hello, world!"); test_string("Feliz Navidad"); test_string("..+>>+>--<[]"); } fn test_string(s: &str) { assert_eq!(run_brainf(&string_to_brainf(s)), s); } fn run_brainf(instructions: &[Instruction]) -> String { let mut output = String::new(); let mut tape = vec![0u8; 1024]; let mut pointer = 512; let mut index = 0; while let Some(instruction) = instructions.get(index) { use Instruction as I; match instruction { I::Left => pointer -= 1, I::Right => pointer += 1, I::Increment => tape[pointer] = tape[pointer].wrapping_add(1), I::Decrement => tape[pointer] = tape[pointer].wrapping_sub(1), I::OpenLoop => unimplemented!(), I::CloseLoop => unimplemented!(), I::Read => panic!("Tried to use `,` but cannot access input in tests."), I::Output => output.push(tape[pointer] as char) } index += 1; } output } }
// TODO: Replace examples and use TDD by writing your own tests. The code provided here is just a how-to example.#include <criterion/criterion.h>#include <string.h>// replace with the actual method being testedint s2b(int argc, char *argv[]);extern char s[];Test(the_multiply_function, should_pass_all_the_tests_provided) {char *argv[] ={"","hello, world!"};s2b(2,argv);cr_assert_eq(strcmp(s,"++++++++[>+++++++++++++<-]>.<++++++++[><-]>---.<>+++++++.<>.<>+++.<++++++++[>--------<-]>---.<>------------.<++++++++[>++++++++++<-]>+++++++.<>--------.<>+++.<++++++++[><-]>------.<>--------.<++++++++[>--------<-]>---.<"), 0);- #[cfg(test)]
- mod tests {
- use super::*;
- #[test]
- fn test() {
- test_string("hello, world!");
- test_string("Feliz Navidad");
- test_string("..+>>+>--<[]");
- }
- fn test_string(s: &str) {
- assert_eq!(run_brainf(&string_to_brainf(s)), s);
- }
- fn run_brainf(instructions: &[Instruction]) -> String {
- let mut output = String::new();
- let mut tape = vec![0u8; 1024];
- let mut pointer = 512;
- let mut index = 0;
- while let Some(instruction) = instructions.get(index) {
- use Instruction as I;
- match instruction {
- I::Left => pointer -= 1,
- I::Right => pointer += 1,
- I::Increment => tape[pointer] = tape[pointer].wrapping_add(1),
- I::Decrement => tape[pointer] = tape[pointer].wrapping_sub(1),
- I::OpenLoop => unimplemented!(),
- I::CloseLoop => unimplemented!(),
- I::Read => panic!("Tried to use `,` but cannot access input in tests."),
- I::Output => output.push(tape[pointer] as char)
- }
- index += 1;
- }
- output
- }
- }
This code now shows how reversing a string works. Reversing a string is just changing the order in which a string is read. New test cases have been added too. If you really wanted the shortest code possible, I am very sorry to upset you. But I can change it if you want to.
def flip_str(string): idx = -1 # Start index for reversing new_string = "" # Create an empty string to store the reversed string for val in string: new_string += string[idx] # Add characters from the original string in reverse order idx -= 1 # Move to the previous character in the original string return new_string
reverse_string = lambda string: "".join(reversed(string))- def flip_str(string):
- idx = -1 # Start index for reversing
- new_string = "" # Create an empty string to store the reversed string
- for val in string:
- new_string += string[idx] # Add characters from the original string in reverse order
- idx -= 1 # Move to the previous character in the original string
- return new_string
import codewars_test as test from solution import flip_str @test.describe("Testing") def a(): @test.it("String Reversal Tests") def a(): test.assert_equals(flip_str(''), '') test.assert_equals(flip_str('a'), 'a') test.assert_equals(flip_str('hello'), 'olleh') test.assert_equals(flip_str('world'), 'dlrow') test.assert_equals(flip_str('hello world'), 'dlrow olleh') test.assert_equals(flip_str('abc123!@#'), '#@!321cba') test.assert_equals(flip_str('HelloWorld'), 'dlroWolleH') test.assert_equals(flip_str('level'), 'level') test.assert_equals(flip_str('abcdefghijklmnopqrstuvwxyz'), 'zyxwvutsrqponmlkjihgfedcba') test.assert_equals(flip_str('1234567890'), '0987654321')
- import codewars_test as test
from solution import reverse_string- from solution import flip_str
@test.describe("Solution")- @test.describe("Testing")
- def a():
@test.it("should test for something")- @test.it("String Reversal Tests")
- def a():
test.assert_equals(reverse_string('abc'), 'cba')test.assert_equals(reverse_string('123'), '321')test.assert_equals(reverse_string('a1b2c3'), '3c2b1a')test.assert_equals(reverse_string('Hello World!'), '!dlroW olleH')test.assert_equals(reverse_string('Capre diem'), 'meid erpaC')test.assert_equals(reverse_string('Lorem ipsum dolor sit amet!'), '!tema tis rolod muspi meroL')test.assert_equals(reverse_string('abcdefghijklmnopqrstuvwxyz'), 'zyxwvutsrqponmlkjihgfedcba')- test.assert_equals(flip_str(''), '')
- test.assert_equals(flip_str('a'), 'a')
- test.assert_equals(flip_str('hello'), 'olleh')
- test.assert_equals(flip_str('world'), 'dlrow')
- test.assert_equals(flip_str('hello world'), 'dlrow olleh')
- test.assert_equals(flip_str('abc123!@#'), '#@!321cba')
- test.assert_equals(flip_str('HelloWorld'), 'dlroWolleH')
- test.assert_equals(flip_str('level'), 'level')
- test.assert_equals(flip_str('abcdefghijklmnopqrstuvwxyz'), 'zyxwvutsrqponmlkjihgfedcba')
- test.assert_equals(flip_str('1234567890'), '0987654321')
Changed function name to be more descriptive.
Changed return type to avoid representation of invalid states.
use std::collections::BTreeMap; fn winning_set_size<T: Ord>(numbers: [T; 5]) -> Option<u8> { let mut counts = BTreeMap::new(); for number in numbers { *counts.entry(number).or_default() += 1; } let largest_set_size = counts.into_values().max().unwrap(); if largest_set_size >= 2 { Some(largest_set_size) } else { None } }
function isWinner(lineInfo){- use std::collections::BTreeMap;
- fn winning_set_size<T: Ord>(numbers: [T; 5]) -> Option<u8> {
- let mut counts = BTreeMap::new();
- for number in numbers {
- *counts.entry(number).or_default() += 1;
- }
- let largest_set_size = counts.into_values().max().unwrap();
- if largest_set_size >= 2 {
- Some(largest_set_size)
- } else {
- None
- }
- }
#[test] fn test() { assert_eq!(winning_set_size([1, 2, 3, 4, 5]), None); assert_eq!(winning_set_size(['1', '1', '3', '4', '5']), Some(2)); assert_eq!(winning_set_size(["1", "1", "1", "4", "5"]), Some(3)); assert_eq!(winning_set_size([true, true, true, true, false]), Some(4)); assert_eq!(winning_set_size([(), (), (), (), ()]), Some(5)); }
// Since Node 10, we're using Mocha.// You can use `chai` for assertions.const chai = require("chai");// 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 return non winner", function() {var result = isWinner(["1", "2", "3", "4", "5"])Test.assertEquals(result[0], false);});it("should return winner with 2 match", function() {var result = isWinner(["1", "1", "3", "4", "5"])Test.assertEquals(result[0], true);Test.assertEquals(result[1], 2);});it("should return winner with 2 match", function() {var result = isWinner([1, 1, 3, 4, 5])Test.assertEquals(result[0], true);Test.assertEquals(result[1], 2);});it("should return winner with 3 match", function() {var result = isWinner(["1", "1", "1", "4", "5"])Test.assertEquals(result[0], true);Test.assertEquals(result[1], 3);});it("should return winner with 3 match", function() {var result = isWinner([1, 1, 1, 4, 5])Test.assertEquals(result[0], true);Test.assertEquals(result[1], 3);});it("should return winner with 4 match", function() {var result = isWinner(["1", "1", "1", "1", "5"])Test.assertEquals(result[0], true);Test.assertEquals(result[1], 4);});it("should return winner with 4 match", function() {var result = isWinner([1, 1, 1, 1, 5])Test.assertEquals(result[0], true);Test.assertEquals(result[1], 4);});it("should return winner with 5 match", function() {var result = isWinner(["1", "1", "1", "1", "1"])Test.assertEquals(result[0], true);Test.assertEquals(result[1], 5);});it("should return winner with 5 match", function() {var result = isWinner([1, 1, 1, 1, 1])Test.assertEquals(result[0], true);Test.assertEquals(result[1], 5);});it("should return winner with 5 match", function() {var result = isWinner([1, "1", 1, "1", "1"])Test.assertEquals(result[0], true);Test.assertEquals(result[1], 5);});});- #[test]
- fn test() {
- assert_eq!(winning_set_size([1, 2, 3, 4, 5]), None);
- assert_eq!(winning_set_size(['1', '1', '3', '4', '5']), Some(2));
- assert_eq!(winning_set_size(["1", "1", "1", "4", "5"]), Some(3));
- assert_eq!(winning_set_size([true, true, true, true, false]), Some(4));
- assert_eq!(winning_set_size([(), (), (), (), ()]), Some(5));
- }
use std::cmp::Reverse; fn sort_by_salary<'a>(workers: &[(&'a str, i32)]) -> Vec<&'a str> { let mut workers = workers.to_vec(); workers.sort_by_key(|&(_, salary)| Reverse(salary)); workers.into_iter().map(|(name, _)| name).collect() }
def sort_by_salary(workers):filtered = list(filter(lambda x: x[1] != "-", workers))if not filtered:return tuple()new = list(sorted(filtered, key=lambda x: int(x[1])))[::-1]return tuple(i[0] for i in new)[:5]- use std::cmp::Reverse;
- fn sort_by_salary<'a>(workers: &[(&'a str, i32)]) -> Vec<&'a str> {
- let mut workers = workers.to_vec();
- workers.sort_by_key(|&(_, salary)| Reverse(salary));
- workers.into_iter().map(|(name, _)| name).collect()
- }
#[test] fn test() { assert_eq!( sort_by_salary(&[("max", 20_000), ("jason", 40_000), ("christian", 70_000), ("carl", 50_000)]), ["christian", "carl", "jason", "max"] ); assert_eq!( sort_by_salary(&[("stephy", 100_000), ("king", 10_000)]), ["stephy", "king"] ); assert_eq!( sort_by_salary(&[("ironman", 20_000), ("batman", 15_000), ("kenobi", 150_000), ("mr. x", 40_000), ("spiderman", 75_000), ("ramsay", 115_000)]), ["kenobi", "ramsay", "spiderman", "mr. x", "ironman", "batman"] ); }
- #[test]
- fn test() {
- assert_eq!(
- sort_by_salary(&[("max", 20_000), ("jason", 40_000), ("christian", 70_000), ("carl", 50_000)]),
- ["christian", "carl", "jason", "max"]
- );
- assert_eq!(
- sort_by_salary(&[("stephy", 100_000), ("king", 10_000)]),
- ["stephy", "king"]
- );
- assert_eq!(
- sort_by_salary(&[("ironman", 20_000), ("batman", 15_000), ("kenobi", 150_000), ("mr. x", 40_000), ("spiderman", 75_000), ("ramsay", 115_000)]),
- ["kenobi", "ramsay", "spiderman", "mr. x", "ironman", "batman"]
- );
- }
Added proper handling of characters that expand when capitalized.
Ajouté la propre gestion des caractères qui se multiplient lorsqu'ils sont capitalisés.
fn maestro_split(s: &str) -> String { let milieu = s.chars().count() / 2; let mut lettres = s.chars(); let côté_gauche: String = (&mut lettres).take(milieu).flat_map(char::to_lowercase).collect(); let lettre_majuscule = lettres.next().map(|c| c.to_uppercase().to_string()).unwrap_or_default(); let côté_droite: String = lettres.flat_map(char::to_lowercase).collect(); format!("{lettre_majuscule}{côté_droite}{côté_gauche}") } fn approche_naïf(s: &str) -> String { if s.is_empty() { return String::new(); } let mid = s.len() / 2; format!("{}{}{}", s[mid..mid+1].to_uppercase(), s[mid+1..].to_lowercase(), s[..mid].to_lowercase()) }
function maestroSplit(string) {let newWord = string.slice(parseInt(string.length / 2)) + string.slice(0, parseInt(string.length / 2));return newWord.toLowerCase().charAt(0).toUpperCase() + newWord.toLowerCase().slice(1);- fn maestro_split(s: &str) -> String {
- let milieu = s.chars().count() / 2;
- let mut lettres = s.chars();
- let côté_gauche: String = (&mut lettres).take(milieu).flat_map(char::to_lowercase).collect();
- let lettre_majuscule = lettres.next().map(|c| c.to_uppercase().to_string()).unwrap_or_default();
- let côté_droite: String = lettres.flat_map(char::to_lowercase).collect();
- format!("{lettre_majuscule}{côté_droite}{côté_gauche}")
- }
- fn approche_naïf(s: &str) -> String {
- if s.is_empty() {
- return String::new();
- }
- let mid = s.len() / 2;
- format!("{}{}{}", s[mid..mid+1].to_uppercase(), s[mid+1..].to_lowercase(), s[..mid].to_lowercase())
- }
#[cfg(test)] mod tests { use super::*; #[test] fn test_ascii() { assert_eq!(maestro_split("verLan"), "Lanver"); assert_eq!(maestro_split("Maestro"), "Stromae"); assert_eq!(maestro_split("MaEsTrO"), "Stromae"); assert_eq!(maestro_split("wArScODE"), "Codewars"); assert_eq!(maestro_split(""), ""); } #[test] fn test_unicode() { assert_eq!(maestro_split("français"), "Çaisfran"); assert_eq!(maestro_split("Æther"), "Heræt"); assert_eq!(maestro_split("𱁬ဪ⸻"), "ဪ⸻𱁬"); assert_eq!(maestro_split("heißen"), "SSenhei"); } #[test] fn test_naïf_correct() { assert_eq!(approche_naïf("verLan"), "Lanver"); assert_eq!(approche_naïf("Maestro"), "Stromae"); assert_eq!(approche_naïf("MaEsTrO"), "Stromae"); assert_eq!(approche_naïf("wArScODE"), "Codewars"); assert_eq!(approche_naïf(""), ""); } #[test] #[should_panic] fn test_naïf_panique1() { approche_naïf("français"); } #[test] #[should_panic] fn test_naïf_panique2() { approche_naïf("heißen"); } #[test] #[should_panic] fn test_naïf_panique3() { approche_naïf("𱁬ဪ⸻"); } }
// 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("maestroSplit", function() {it("should transform verLan to Lanver", () => {Test.assertEquals(maestroSplit("verLan"), "Lanver");});it("should transform français to Çaisfran", () => {Test.assertEquals(maestroSplit("français"), "Çaisfran");});it("should transform Maestro to Stromae", () => {// Test.assertEquals(1 + 1, 2);// assert.strictEqual(1 + 1, 2);Test.assertEquals(maestroSplit("Maestro"), "Stromae");});it("should transform MaEsTrO to Stromae", () => {Test.assertEquals(maestroSplit("MaEsTrO"), "Stromae");});it("should transform warscode to Codewars", () => {Test.assertEquals(maestroSplit("wArScODE"), "Codewars");});});- #[cfg(test)]
- mod tests {
- use super::*;
- #[test]
- fn test_ascii() {
- assert_eq!(maestro_split("verLan"), "Lanver");
- assert_eq!(maestro_split("Maestro"), "Stromae");
- assert_eq!(maestro_split("MaEsTrO"), "Stromae");
- assert_eq!(maestro_split("wArScODE"), "Codewars");
- assert_eq!(maestro_split(""), "");
- }
- #[test]
- fn test_unicode() {
- assert_eq!(maestro_split("français"), "Çaisfran");
- assert_eq!(maestro_split("Æther"), "Heræt");
- assert_eq!(maestro_split("𱁬ဪ⸻"), "ဪ⸻𱁬");
- assert_eq!(maestro_split("heißen"), "SSenhei");
- }
- #[test]
- fn test_naïf_correct() {
- assert_eq!(approche_naïf("verLan"), "Lanver");
- assert_eq!(approche_naïf("Maestro"), "Stromae");
- assert_eq!(approche_naïf("MaEsTrO"), "Stromae");
- assert_eq!(approche_naïf("wArScODE"), "Codewars");
- assert_eq!(approche_naïf(""), "");
- }
- #[test] #[should_panic]
- fn test_naïf_panique1() {
- approche_naïf("français");
- }
- #[test] #[should_panic]
- fn test_naïf_panique2() {
- approche_naïf("heißen");
- }
- #[test] #[should_panic]
- fn test_naïf_panique3() {
- approche_naïf("𱁬ဪ⸻");
- }
- }
fn other_angle(angle1: u32, angle2: u32) -> u32 { 180 - (angle1 + angle2) }
public class ThirdAngle {public static int otherAngle(int angle1, int angle2) {return 180-(angle1+angle2);}- fn other_angle(angle1: u32, angle2: u32) -> u32 {
- 180 - (angle1 + angle2)
- }
#[test] fn test() { assert_eq!(other_angle(40, 80), 60); assert_eq!(other_angle(108, 24), 48); assert_eq!(other_angle(5, 5), 170); assert_eq!(other_angle(90, 0), 90); }
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 testspublic class SolutionTest {@Testpublic void testSomething() {// assertEquals("expected", "actual");}- #[test]
- fn test() {
- assert_eq!(other_angle(40, 80), 60);
- assert_eq!(other_angle(108, 24), 48);
- assert_eq!(other_angle(5, 5), 170);
- assert_eq!(other_angle(90, 0), 90);
- }
fn find_index(slice: &[i32], value: i32) -> Option<usize> { slice.iter().position(|&num| num == value) }
public class Kata {public static int findIndex (int[] my_array, int t) {// Find the index of treturn 4;}- fn find_index(slice: &[i32], value: i32) -> Option<usize> {
- slice.iter().position(|&num| num == value)
- }
#[test] fn test() { let array = [1, 2, 5, 7, 10]; assert_eq!(find_index(&array, 1), Some(0)); assert_eq!(find_index(&array, 2), Some(1)); assert_eq!(find_index(&array, 5), Some(2)); assert_eq!(find_index(&array, 7), Some(3)); assert_eq!(find_index(&array, 10), Some(4)); assert_eq!(find_index(&array, -1), None); }
import org.junit.jupiter.api.Test;import static org.junit.jupiter.api.Assertions.assertEquals;// TODO: Replace examples and use TDD by writing your own testsclass SolutionTest {@Testvoid testSomething() {int[] randomArray = {1, 2, 5, 7};assertEquals(2, Kata.findIndex(randomArray, 5));}}- #[test]
- fn test() {
- let array = [1, 2, 5, 7, 10];
- assert_eq!(find_index(&array, 1), Some(0));
- assert_eq!(find_index(&array, 2), Some(1));
- assert_eq!(find_index(&array, 5), Some(2));
- assert_eq!(find_index(&array, 7), Some(3));
- assert_eq!(find_index(&array, 10), Some(4));
- assert_eq!(find_index(&array, -1), None);
- }