Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/java/com/ordestiny/tdd/functions/MissingNumber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.ordestiny.tdd.functions;

class MissingNumber {

static int getMissingNo(int numberArray[]) {

int n = numberArray.length;
int i, total;
total = (n + 1) * (n + 2) / 2;
for (i = 0; i < n; i++)
total -= numberArray[i];
return total;
}
}
27 changes: 27 additions & 0 deletions src/test/java/com/ordestiny/tdd/functions/MissingNumberTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.ordestiny.tdd.functions;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

class MissingNumberTest {


@Test
public void testMissingNumberFail() {

int a[] = {1, 2, 4, 5, 6};
int missedNumber = MissingNumber.getMissingNo(a);
// assert
assertEquals(7, missedNumber);
Comment on lines +12 to +15
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you didn't pass this test
the missed Number here should be. 3 , not 7

}


@Test
public void testMissingNumberPassed() {

int a[] = {1, 2, 3, 4, 5, 6, 8};
int missedNumber = MissingNumber.getMissingNo(a);
// assert
assertEquals(7, missedNumber);
}
}