From 5636da9fbb4b70e74737a854f3ecf8653b606194 Mon Sep 17 00:00:00 2001 From: hoducdat <42961190+hoducdat@users.noreply.github.com> Date: Fri, 20 May 2022 23:02:19 +0700 Subject: [PATCH 1/2] Create mcc_report.md --- .../algorithms/math/mcc_report.md | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/test/java/com/williamfiset/algorithms/math/mcc_report.md diff --git a/src/test/java/com/williamfiset/algorithms/math/mcc_report.md b/src/test/java/com/williamfiset/algorithms/math/mcc_report.md new file mode 100644 index 000000000..2cafe7176 --- /dev/null +++ b/src/test/java/com/williamfiset/algorithms/math/mcc_report.md @@ -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 | + From e3f8a1425129625e6e339ff17b3a134ae792e3da Mon Sep 17 00:00:00 2001 From: hoducdat <42961190+hoducdat@users.noreply.github.com> Date: Fri, 20 May 2022 23:15:20 +0700 Subject: [PATCH 2/2] Upload all du path testing function --- .../algorithms/math/PrimeTest.java | 32 +++++++++++++++ .../algorithms/math/all-du-path.md | 40 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 src/test/java/com/williamfiset/algorithms/math/PrimeTest.java create mode 100644 src/test/java/com/williamfiset/algorithms/math/all-du-path.md diff --git a/src/test/java/com/williamfiset/algorithms/math/PrimeTest.java b/src/test/java/com/williamfiset/algorithms/math/PrimeTest.java new file mode 100644 index 000000000..3372679f7 --- /dev/null +++ b/src/test/java/com/williamfiset/algorithms/math/PrimeTest.java @@ -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"); + } + + } + + } +} diff --git a/src/test/java/com/williamfiset/algorithms/math/all-du-path.md b/src/test/java/com/williamfiset/algorithms/math/all-du-path.md new file mode 100644 index 000000000..439935824 --- /dev/null +++ b/src/test/java/com/williamfiset/algorithms/math/all-du-path.md @@ -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 |