using System; using System.Linq; using System.Collections.Generic; namespace Kumite { public class Problem { public static int SumDigitsOf(long integer) => (int)(from ch in integer.ToString() where Char.IsDigit(ch) select Char.GetNumericValue(ch)).Sum(); } }
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace Kumite
- {
- public class Problem
- {
public static int SumDigitsOf(long integer){return (int)(from ch in integer.ToString()- public static int SumDigitsOf(long integer) => (int)(from ch in integer.ToString()
- where Char.IsDigit(ch)
- select Char.GetNumericValue(ch)).Sum();
}- }
- }
Fundamentals
Numbers
Data Types
Logic
public class Math { public static int Max(int a, int b) => (a > b) ? a : b; }
- public class Math
- {
public int Max(int a, int b){return (a > b) ? a : b;}- public static int Max(int a, int b) => (a > b) ? a : b;
- }
namespace Solution { using NUnit.Framework; [TestFixture] public class SolutionTest { [Test] [TestCase(1,2,2)] [TestCase(2,1,2)] [TestCase(1,1,1)] public void Max_WhenCalled_ReturnTheGreaterArgument(int a, int b, int expectedResult) { var result = Math.Max(a,b); Assert.That(result, Is.EqualTo(expectedResult)); } } }
- namespace Solution {
- using NUnit.Framework;
- [TestFixture]
- public class SolutionTest
- {
private Math math;[SetUp]public void SetUp(){math = new Math();}- [Test]
- [TestCase(1,2,2)]
- [TestCase(2,1,2)]
- [TestCase(1,1,1)]
- public void Max_WhenCalled_ReturnTheGreaterArgument(int a, int b, int expectedResult)
- {
var result = math.Max(a,b);- var result = Math.Max(a,b);
- Assert.That(result, Is.EqualTo(expectedResult));
- }
- }
- }