Skip to content

Commit

Permalink
rearanged everything. added pytests
Browse files Browse the repository at this point in the history
  • Loading branch information
MKS2345 committed Oct 23, 2024
1 parent 117b881 commit e0620dd
Show file tree
Hide file tree
Showing 43 changed files with 701 additions and 472 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Run Tests

on: [push, pull_request]

jobs:
sanity_tests:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9' # Adjust this version as necessary

- name: Install dependencies
run: |
python -m venv .venv
.venv/bin/pip install -r requirements.txt
- name: Run sanity tests
run: |
# Run each test individually
for test_name in test_is_true test_equals test_not_equals test_is_not_true test_greater_than test_greater_than_or_equal_to test_not_one test_less_than test_positive_check test_is_even test_is_odd test_is_not_negative test_is_zero test_absolute_value test_is_non_zero test_sum test_difference test_division test_factorial test_string_equality
do
echo "Running $test_name"
.venv/bin/pytest resources/tests/return_tests.py::"$test_name" -s
done
remaining_tests:
runs-on: ubuntu-latest
needs: sanity_tests # This ensures that this job runs after the sanity tests

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9' # Adjust this version as necessary

- name: Install dependencies
run: |
python -m venv .venv
.venv/bin/pip install -r requirements.txt
- name: Run remaining tests
run: |
# Run the remaining test individually
.venv/bin/pytest resources/tests/return_remaining_tests.py::test_remaining_return -s
7 changes: 5 additions & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 0 additions & 71 deletions autos/auto.py

This file was deleted.

60 changes: 0 additions & 60 deletions main.py

This file was deleted.

2 changes: 1 addition & 1 deletion qodana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ linter: jetbrains/qodana-python:2024.1
exclude:
- name: All
paths:
- compile
- resources
- name: PyPep8NamingInspection
- name: PyInterpreterInspection
- name: PyUnusedLocalInspection
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python-3.13
pytest
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions resources/tests/return_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import random

import pytest
import itertools

import src.main

def test_remaining_return():
zero_params = []
for i in range(48):
zero_params.append(0)
zero_params = tuple(zero_params)


# Define the range of values
values = range(-127, 128) # from -127 to 127, inclusive

sample_size = 1000000 # Adjust this to any reasonable number for sampling

for _ in range(sample_size):
# Generate a random combination of 8 parameters
combination = tuple(random.randint(-127, 127) for _ in range(8))

result = src.main.robot(*combination, *zero_params)
result = list(result)
for i in range(len(result)):
if i > 7:
result.pop(8)
result = tuple(result)


# Check if the expected condition holds true for the specific spot
# For example, let's check if the first value in the result is equal to 0
if combination[0] == 0:
assert result[0] == 0 # Adjust this condition as needed
135 changes: 135 additions & 0 deletions resources/tests/sanity_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import pytest

def test_is_true():
assert True

def test_equals():
for i in [-3, -2, -1, 0, 1, 2, 3]:
assert equal(i)

def test_not_equals():
for i in [-3, -2, -1, 0, 1, 2, 3]:
assert not_equal(i, i+1)

def not_equal(a, b):
return a != b

def equal(a):
return a == a

def test_is_not_true():
assert not False

def test_greater_than():
tuples_list = [(x, y) for x in range(10) for y in range(10) if x > y]
for i in range(len(tuples_list)):
assert greater_than(tuples_list[i][0], tuples_list[i][1])

def greater_than(a, b):
return a > b

def test_greater_than_or_equal_to():
tuples_list = [(x, y) for x in range(10) for y in range(10) if x >= y]
for i in range(len(tuples_list)):
assert greater_than_or_equal_to(tuples_list[i][0], tuples_list[i][1])

def greater_than_or_equal_to(a, b):
return a >= b

def test_not_one():
assert not 1 == 0

def test_less_than():
tuples_list = [(x, y) for x in range(10) for y in range(10) if x < y]
for i in range(len(tuples_list)):
assert less_than(tuples_list[i][0], tuples_list[i][1])

def less_than(a, b):
return a < b

def test_positive_check():
for i in [1, 2, 3, 4, 5]:
assert is_positive(i)

def is_positive(a):
return a > 0

def test_is_even():
for i in [0, 2, 4, 6, 8]:
assert is_even(i)

def is_even(a):
return a % 2 == 0

def test_is_odd():
for i in [1, 3, 5, 7, 9]:
assert is_odd(i)

def is_odd(a):
return a % 2 != 0

def test_is_not_negative():
for i in [0, 1, 2, 3, 4]:
assert not_negative(i)

def not_negative(a):
return a >= 0

def test_is_zero():
assert is_zero(0)

def is_zero(a):
return a == 0

def test_absolute_value():
for i in [-1, -2, -3]:
assert abs(i) == -i

def test_is_non_zero():
for i in [1, -1, 2, -2, 3]:
assert is_non_zero(i)

def is_non_zero(a):
return a != 0

def test_sum():
assert sum_two(2, 3) == 5

def sum_two(a, b):
return a + b

def test_difference():
assert difference(5, 3) == 2

def difference(a, b):
return a - b

def test_division():
assert divide(6, 3) == 2
assert divide(5, 2) == 2.5

def divide(a, b):
return a / b if b != 0 else None

def test_factorial():
assert factorial(0) == 1
assert factorial(1) == 1
assert factorial(2) == 2
assert factorial(3) == 6
assert factorial(4) == 24
assert factorial(5) == 120

def factorial(n):
if n == 0:
return 1
result = 1
for i in range(1, n + 1):
result *= i
return result

def test_string_equality():
assert string_equal("hello", "hello")
assert not string_equal("hello", "world")

def string_equal(a, b):
return a == b
File renamed without changes.
Loading

0 comments on commit e0620dd

Please sign in to comment.