using System; public static class Kata { public static int SameCase(char a, char b) { var aZ = a <= 'Z'; var bZ = b <= 'Z'; var aIsLetter = a >= 'A' && a <= 'z' && (aZ || a >= 'a'); if (aIsLetter != (b >= 'A' && b <= 'z' && (bZ || b >= 'a'))) return -1; return (!aIsLetter || aZ == bZ) ? 1 : 0; } }
- using System;
- public static class Kata
- {
- public static int SameCase(char a, char b)
- {
if (!char.IsLetter(a) && !char.IsLetter(b))return 1;if (!char.IsLetter(a) || !char.IsLetter(b))return -1;return (char.IsUpper(a) == char.IsUpper(b)) ? 1 : 0;- var aZ = a <= 'Z';
- var bZ = b <= 'Z';
- var aIsLetter = a >= 'A' && a <= 'z' && (aZ || a >= 'a');
- if (aIsLetter != (b >= 'A' && b <= 'z' && (bZ || b >= 'a'))) return -1;
- return (!aIsLetter || aZ == bZ) ? 1 : 0;
- }
- }
namespace Solution { using NUnit.Framework; using System; [TestFixture] public class SolutionTest { [Test] [Repeat(1000)] 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')); Assert.AreEqual(1, Kata.SameCase('1', '2')); } [Test] [Repeat(1000)] 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] [Repeat(1000)] 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] [Repeat(1000)] public void RandomTest() { string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmopqrstuvwxyz1234567890~/*-+:.,><.#@!&"; Random rand = new Random(0); 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 (!char.IsLetter(a) || !char.IsLetter(b)) return -1; if ((a >= 97) == (b >= 97)) return 1; return 0; } } }
- namespace Solution {
- using NUnit.Framework;
- using System;
- [TestFixture]
- public class SolutionTest
- {
- [Test]
- [Repeat(1000)]
- 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'));
- Assert.AreEqual(1, Kata.SameCase('1', '2'));
- }
- [Test]
- [Repeat(1000)]
- 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]
- [Repeat(1000)]
- 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]
- [Repeat(1000)]
- public void RandomTest() {
- string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmopqrstuvwxyz1234567890~/*-+:.,><.#@!&";
Random rand = new Random();- Random rand = new Random(0);
- 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 (!char.IsLetter(a) || !char.IsLetter(b)) return -1;
- if ((a >= 97) == (b >= 97)) return 1;
- return 0;
- }
- }
- }