Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fafb49b

Browse files
committed
Added generation of ugly numbers
1 parent fc77cc4 commit fafb49b

File tree

1 file changed

+29
-4
lines changed
  • CodingInterview/CodingInterview

1 file changed

+29
-4
lines changed

‎CodingInterview/CodingInterview/Tests.cs‎

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,21 @@ private static bool CheckIfUgly(int number)
249249
return false;
250250
}
251251

252+
public int[] GenerateUglyNumbersArray(int count)
253+
{
254+
var list = new HashSet<int> {1};
255+
for (var index = 1; index <= count; index++)
256+
{
257+
list.Add(index * 2);
258+
list.Add(index * 3);
259+
list.Add(index * 5);
260+
}
261+
262+
var newList = list.ToList();
263+
newList.Sort();
264+
return newList.Take(count).ToArray();
265+
}
266+
252267
[Test]
253268
public void RemoveDuplicatesFromSortedArray_1()
254269
{
@@ -383,9 +398,9 @@ public void ContainsDuplicates_82(int []inputArray, bool isDuplicateElement)
383398
{
384399
//given
385400
//when
386-
var isPalindrome = CheckIfArrayContainsDuplicatedElements(inputArray);
401+
var containsDuplicateStatus = CheckIfArrayContainsDuplicatedElements(inputArray);
387402
//then
388-
Assert.AreEqual(isDuplicateElement, isPalindrome);
403+
Assert.AreEqual(isDuplicateElement, containsDuplicateStatus);
389404
}
390405

391406
[Test]
@@ -399,10 +414,20 @@ public void CheckUglyNumbers_99(int number, bool isUgly)
399414
{
400415
//given
401416
//when
402-
var isPalindrome = CheckIfUgly(number);
417+
var uglyStatus = CheckIfUgly(number);
403418
//then
404-
Assert.AreEqual(isUgly, isPalindrome);
419+
Assert.AreEqual(isUgly, uglyStatus);
405420
}
406421

422+
[Test]
423+
[TestCase(10, new []{ 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 })]
424+
public void CheckUglyNumbers2_100(int numberOfUglyNumbers, int[] arrayWithUglyNumbers)
425+
{
426+
//given
427+
//when
428+
var arrayWithUglyNumbersGenerated = GenerateUglyNumbersArray(numberOfUglyNumbers);
429+
//then
430+
Assert.AreEqual(arrayWithUglyNumbers, arrayWithUglyNumbersGenerated);
431+
}
407432
}
408433
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /