public class Kata { public static int sameCase(char a, char b) { if ((Character.isLowerCase(a) && Character.isLowerCase(b)) || (Character.isUpperCase(a) && Character.isUpperCase(b))) { return 1; } return Character.isLetter(a) && Character.isLetter(b) ? 0 : -1; } }
public static class Kata{public static int SameCase(char a, char b){return (char.IsLetter(a) && char.IsLetter(b))? (char.IsUpper(a) && char.IsUpper(b)) || (char.IsLower(a) && char.IsLower(b))? 1 : 0: -1;}- public class Kata {
- public static int sameCase(char a, char b) {
- if ((Character.isLowerCase(a) && Character.isLowerCase(b)) ||
- (Character.isUpperCase(a) && Character.isUpperCase(b))) {
- return 1;
- }
- return Character.isLetter(a) && Character.isLetter(b) ? 0 : -1;
- }
- }
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class KataTest { @Test void testCheck_same_case() { assertEquals(1, Kata.sameCase('a', 'g')); assertEquals(1, Kata.sameCase('A', 'C')); assertEquals(0, Kata.sameCase('b', 'G')); assertEquals(0, Kata.sameCase('B', 'g')); assertEquals(-1, Kata.sameCase('0', '?')); } }
namespace Solution {using NUnit.Framework;using System;- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
[TestFixture]public class SolutionTest{[Test]public void TrueTests(){Assert.AreEqual(1, Kata.SameCase('a', 'u'));Assert.AreEqual(1, Kata.SameCase('A', 'U'));Assert.AreEqual(1, Kata.SameCase('Q', 'P'));Assert.AreEqual(1, Kata.SameCase('w', 'y'));Assert.AreEqual(1, Kata.SameCase('c', 'm'));Assert.AreEqual(1, Kata.SameCase('N', 'W'));}[Test]public void FalseTests(){Assert.AreEqual(0, Kata.SameCase('a', 'U'));Assert.AreEqual(0, Kata.SameCase('A', 'u'));Assert.AreEqual(0, Kata.SameCase('Q', 'p'));Assert.AreEqual(0, Kata.SameCase('w', 'Y'));Assert.AreEqual(0, Kata.SameCase('c', 'M'));Assert.AreEqual(0, Kata.SameCase('N', 'w'));}[Test]public void NotLetters(){Assert.AreEqual(-1, Kata.SameCase('a', '*'));Assert.AreEqual(-1, Kata.SameCase('A', '%'));Assert.AreEqual(-1, Kata.SameCase('Q', '1'));Assert.AreEqual(-1, Kata.SameCase('w', '-'));Assert.AreEqual(-1, Kata.SameCase('c', '8'));Assert.AreEqual(-1, Kata.SameCase('N', ':'));}[Test]public void RandomTest() {string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmopqrstuvwxyz1234567890~/*-+:.,><.#@!&";Random rand = new Random();char char1 = 'a';char char2 = 'a';for (int i = 0; i < 200; i++) {char1 = chars[rand.Next(0,76)];char2 = chars[rand.Next(0,76)];Assert.AreEqual(SameCaseSolution(char1,char2), Kata.SameCase(char1, char2));}}private static int SameCaseSolution(char a, char b) {if (!char.IsLetter(a) || !char.IsLetter(b)) return -1;if ((a >= 97) == (b >= 97)) return 1;return 0;}}}- public class KataTest {
- @Test
- void testCheck_same_case() {
- assertEquals(1, Kata.sameCase('a', 'g'));
- assertEquals(1, Kata.sameCase('A', 'C'));
- assertEquals(0, Kata.sameCase('b', 'G'));
- assertEquals(0, Kata.sameCase('B', 'g'));
- assertEquals(-1, Kata.sameCase('0', '?'));
- }
- }