Question: Write a Unit Tests for this codes Python Code: bool is_prime(int n) { if (n

Write a Unit Tests for this codes

Python Code:

bool is_prime(int n) {

if (n <= 1) {

return false;

}

for (int i = 2; i <= sqrt(n); i++) {

if (n % i == 0) {

return false;

}

}

return true;

}

C++ Code:

#include

#include

bool is_prime(int n) {

if (n <= 1) {

return false;

}

for (int i = 2; i <= sqrt(n); i++) {

if (n % i == 0) {

return false;

}

}

return true;

}

int main() {

int n;

std::cout << "Enter a positive integer: ";

std::cin >> n;

if (is_prime(n)) {

std::cout << n << " is a prime number." << std::endl;

} else {

std::cout << n << " is not a prime number." << std::endl;

}

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!