'1' and '2' are technically of the same case + it seems more intuitive TBH
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; } }
- 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 -1;
- return (char.IsUpper(a) == char.IsUpper(b)) ? 1 : 0;
- }
- }
namespace Solution { using NUnit.Framework; using System; [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')); Assert.AreEqual(1, Kata.SameCase('1', '2')); } [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 (!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]
- 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]
- 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 (!char.IsLetter(a) || !char.IsLetter(b)) return -1;
- if ((a >= 97) == (b >= 97)) return 1;
- return 0;
- }
- }
- }