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
32 changes: 32 additions & 0 deletions src/test/java/com/williamfiset/algorithms/math/PrimeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.williamfiset.algorithms.math;

import org.junit.Test;

public class PrimeTest {
@Test
public void testPrimeSieve() {
int[] limitArray = {8, 9, 15};
for (int i = 0; i < limitArray.length; i++) {
long[] response = CompressedPrimeSieve.primeSieve(limitArray[i]);
if (limitArray[i] == 8 && response[0] == 1) {
System.out.println("Pass");
} else if (limitArray[i] == 8 && response[0] != 1) {
System.out.println("Fail");
}

if (limitArray[i] == 9 && response[0] == 17) {
System.out.println("Pass");
} else if (limitArray[i] == 9 && response[0] != 17) {
System.out.println("Fail");
}

if (limitArray[i] == 15 && response[0] == 145) {
System.out.println("Pass");
} else if (limitArray[i] == 15 && response[0] != 145) {
System.out.println("Fail");
}

}

}
}
40 changes: 40 additions & 0 deletions src/test/java/com/williamfiset/algorithms/math/all-du-path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Test Report for All-DU Path
Source file:
> https://github.com/williamfiset/Algorithms/blob/master/src/main/java/com/williamfiset/algorithms/math/CompressedPrimeSieve.java

Function for testing: primeSieve()
This function do:
> Returns an array of longs with each bit indicating whether a number is prime or not. Use the isNotSet and setBit methods to toggle to bits for each number.

Function code:
```
public static long[] primeSieve(int limit) {
final int numChunks = (int) Math.ceil(limit / NUM_BITS);
final int sqrtLimit = (int) Math.sqrt(limit);
long[] chunks = new long[numChunks];
chunks[0] = 1; // 1 as not prime
for (int i = 3; i <= sqrtLimit; i += 2)
if (isNotSet(chunks, i))
for (int j = i * i; j <= limit; j += i)
if (isNotSet(chunks, j)) {
setBit(chunks, j);
}
return chunks;
}
```
![alt text](https://drive.google.com/uc?id=12iKHCBtJjex9ZX0XL69J-nCZTHkXsq1y)

## Graphs

### Flow chart
![alt text](https://drive.google.com/uc?id=1DjkmdT-PoequO10YDOr8me2rv2Fyml_N)

### Data flow chart
![alt text](https://drive.google.com/uc?id=1bEj7ITLlfcHAsz3gF_HUin3HIlbKLEnh)

### All DU path coverage testcase

| Path | Test case | Expected output | Actual output | Result |
|-------------|------------|-----------------------------|-----------------------------|--------|
| 1->2-5 | limit = 10 | numChunks = 0 sqrtLimit = 3 | numChunks = 0 sqrtLimit = 3 | Pass |
| 1->2-5 -> 8 | limit = 10 | numChunks = 0 sqrtLimit = 3 | numChunks = 0 sqrtLimit = 3 | Pass |
45 changes: 45 additions & 0 deletions src/test/java/com/williamfiset/algorithms/math/mcc_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Test Report for MCC
Source file:
> https://github.com/williamfiset/Algorithms/blob/master/src/main/java/com/williamfiset/algorithms/math/CompressedPrimeSieve.java

Function for testing: primeSieve()
This function do:
> Returns an array of longs with each bit indicating whether a number is prime or not. Use the isNotSet and setBit methods to toggle to bits for each number.

Function code:
```
public static long[] primeSieve(int limit) {
final int numChunks = (int) Math.ceil(limit / NUM_BITS);
final int sqrtLimit = (int) Math.sqrt(limit);
long[] chunks = new long[numChunks];
chunks[0] = 1; // 1 as not prime
for (int i = 3; i <= sqrtLimit; i += 2)
if (isNotSet(chunks, i))
for (int j = i * i; j <= limit; j += i)
if (isNotSet(chunks, j)) {
setBit(chunks, j);
}
return chunks;
}
```
![alt text](https://drive.google.com/uc?id=12iKHCBtJjex9ZX0XL69J-nCZTHkXsq1y)

## Graphs

### Flow chart
![alt text](https://drive.google.com/uc?id=1DjkmdT-PoequO10YDOr8me2rv2Fyml_N)

### Control-flow graph
![alt text](https://drive.google.com/uc?id=1cLUdTxec5WJBWkyrNpk2vEmLs8Y0I8SY)
### MCC Coverage testcase
| Path | i <= sqrtLimit | isNotSet(chunk, i) | j <= limit | isNotSet(chunk,j) | Test case | Expected output | Actual output | Result |
|--------------------------------------------------------|----------------|--------------------|------------|-------------------|-------------------------|-------------------|-------------------|--------|
| 1 -> 2-5 -> 6 -> 7 -> 6 -> 12-13 | F | | | | limit = 8 | [1] | [1] | PASS |
| 1 -> 2-5 -> 6 -> 7 -> 6 -> 12-13 | T | T | | | limit = 9 | [17] | [17] | PASS |
| 1 -> 2-5 -> 6 -> 7 -> 6 -> 12-13 | T | F | | | limit = 100 (and i = 9) | [823970606298257] | [823970606298257] | PASS |
| 1 -> 2-5 -> 6 -> 7 -> 6 -> 12-13 | | F | | | limit = 8 | [1] | [1] | PASS |
| 1 -> 2-5 -> 6 -> 7 ->8 -> 6-> 12-13 | T | T | F | | Not happened | [1] | [1] | PASS |
| 1 -> 2-5 -> 6 -> 7 ->8 -> 6-> 12-13 | T | T | T | | limit = 15 | [145] | [145] | PASS |
| 1 -> 2-5 -> 6 -> 7 ->8 -> 9 -> 8 -> 6-> 12-13 | T | T | T | F | limit = 15 (and j = 12) | [145] | [145] | PASS |
| 1 -> 2-5 -> 6 -> 7 ->8 -> 9 -> 10-11 -> 8 -> 6-> 12-13 | T | T | T | T | limit = 15 | [145] | [145] | PASS |