05 Skills Test
In [1]:
Copied!
from creator import create
from creator import create
In [2]:
Copied!
!ls ~/.cache/open_creator/skill_library
!ls ~/.cache/open_creator/skill_library
ask_run_code_confirm extract_pdf_section solve_24 count_prime_numbers extract_section_from_pdf solve_game_of_24 create filter_prime_numbers solve_quadratic_equation create_api game_of_24 solve_random_maze create_scatter_plot game_of_24_solver display_markdown_message list_python_functions
In [3]:
Copied!
import os
skill_path = os.path.join(os.path.expanduser("~"), ".cache", "open_creator", "skill_library", "filter_prime_numbers")
skill = create(skill_path=skill_path)
import os
skill_path = os.path.join(os.path.expanduser("~"), ".cache", "open_creator", "skill_library", "filter_prime_numbers")
skill = create(skill_path=skill_path)
In [4]:
Copied!
skill.show()
skill.show()
Skill Details: • Name: filter_prime_numbers • Description: This skill filters the number of prime numbers in a given range. • Version: 1.0.0 • Usage: filter_prime_numbers(2, 201) • Parameters: • start (integer): The starting number of the range. • Required: True • end (integer): The ending number of the range. • Required: True • Returns: • count (integer): The number of prime numbers in the given range.
In [5]:
Copied!
# since unitests output does not work in notebook properly, we will directly show its output markdown
test_summary = skill.test()
# since unitests output does not work in notebook properly, we will directly show its output markdown
test_summary = skill.test()
Output()
Output()
Output()
In [6]:
Copied!
test_summary.show()
test_summary.show()
Test Summary Test Case 0 • Test Input: (2, 10) • Run Command: filter_prime_numbers(2, 10) • Expected Result: 4 • Actual Result: 4 • Is Passed: Yes ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────── Test Case 1 • Test Input: (11, 20) • Run Command: filter_prime_numbers(11, 20) • Expected Result: 4 • Actual Result: 4 • Is Passed: Yes ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────── Test Case 2 • Test Input: (21, 30) • Run Command: filter_prime_numbers(21, 30) • Expected Result: 2 • Actual Result: 2 • Is Passed: Yes ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────── Test Case 3 • Test Input: (31, 40) • Run Command: filter_prime_numbers(31, 40) • Expected Result: 2 • Actual Result: 2 • Is Passed: Yes ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────── Test Case 4 • Test Input: (41, 50) • Run Command: filter_prime_numbers(41, 50) • Expected Result: 3 • Actual Result: 3 • Is Passed: Yes ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
In [7]:
Copied!
def filter_prime_numbers(start, end):
def isPrime(num):
if num < 2:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
count = 0
for num in range(start, end + 1):
if isPrime(num):
count += 1
return count
def filter_prime_numbers(start, end):
def isPrime(num):
if num < 2:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
count = 0
for num in range(start, end + 1):
if isPrime(num):
count += 1
return count
In [8]:
Copied!
import unittest
class TestFilterPrimeNumbers(unittest.TestCase):
def test_case_1(self):
self.assertEqual(filter_prime_numbers(2, 10), 4)
def test_case_2(self):
self.assertEqual(filter_prime_numbers(11, 20), 4)
def test_case_3(self):
self.assertEqual(filter_prime_numbers(21, 30), 2)
def test_case_4(self):
self.assertEqual(filter_prime_numbers(31, 40), 2)
def test_case_5(self):
self.assertEqual(filter_prime_numbers(41, 50), 3)
import io
stream = io.StringIO()
runner = unittest.TextTestRunner(stream=stream)
unittest_result = runner.run(unittest.TestLoader().loadTestsFromTestCase(TestFilterPrimeNumbers))
assert len(unittest_result.failures) == 0, stream.getvalue()
import unittest
class TestFilterPrimeNumbers(unittest.TestCase):
def test_case_1(self):
self.assertEqual(filter_prime_numbers(2, 10), 4)
def test_case_2(self):
self.assertEqual(filter_prime_numbers(11, 20), 4)
def test_case_3(self):
self.assertEqual(filter_prime_numbers(21, 30), 2)
def test_case_4(self):
self.assertEqual(filter_prime_numbers(31, 40), 2)
def test_case_5(self):
self.assertEqual(filter_prime_numbers(41, 50), 3)
import io
stream = io.StringIO()
runner = unittest.TextTestRunner(stream=stream)
unittest_result = runner.run(unittest.TestLoader().loadTestsFromTestCase(TestFilterPrimeNumbers))
assert len(unittest_result.failures) == 0, stream.getvalue()
Last update:
October 31, 2023
Created: October 18, 2023
Created: October 18, 2023