public class Program { public static int FindSquaresInArray(int[] arr){ int sum = 0; foreach(int item in arr) { sum += item * item; } return sum; } }
using System.Linq;- public class Program
- {
- public static int FindSquaresInArray(int[] arr){
return arr.Sum(x => x * x);- int sum = 0;
- foreach(int item in arr)
- {
- sum += item * item;
- }
- return sum;
- }
- }
using NUnit.Framework; namespace Solution { [TestFixture] public class SolutionTest { [Test] public void TestEmptyArray() { int[] emptyArray = new int[0]; Assert.AreEqual(0, Program.FindSquaresInArray(emptyArray)); } [Test] public void TestArrayWithPositiveIntegers() { int[] positiveArray = { 1, 2, 3, 4, 5 }; Assert.AreEqual(55, Program.FindSquaresInArray(positiveArray)); } [Test] public void TestArrayWithSingleElement() { int[] singleElementArray = { 4 }; Assert.AreEqual(16, Program.FindSquaresInArray(singleElementArray)); } [Test] public void TestArrayWithAllZeros() { int[] zeroArray = { 0, 0, 0, 0 }; Assert.AreEqual(0, Program.FindSquaresInArray(zeroArray)); } } }
- using NUnit.Framework;
using System;- namespace Solution
- {
- [TestFixture]
- public class SolutionTest
- {
- [Test]
- public void TestEmptyArray()
- {
- int[] emptyArray = new int[0];
- Assert.AreEqual(0, Program.FindSquaresInArray(emptyArray));
- }
- [Test]
- public void TestArrayWithPositiveIntegers()
- {
- int[] positiveArray = { 1, 2, 3, 4, 5 };
- Assert.AreEqual(55, Program.FindSquaresInArray(positiveArray));
- }
- [Test]
- public void TestArrayWithSingleElement()
- {
- int[] singleElementArray = { 4 };
- Assert.AreEqual(16, Program.FindSquaresInArray(singleElementArray));
- }
- [Test]
- public void TestArrayWithAllZeros()
- {
- int[] zeroArray = { 0, 0, 0, 0 };
- Assert.AreEqual(0, Program.FindSquaresInArray(zeroArray));
- }
- }
- }