Commit c5ffa0f9 authored by Disha  Baghele's avatar Disha Baghele
Browse files

sum feature added

parents
Pipeline #147 passed with stages
in 2 seconds
Showing with 69 additions and 0 deletions
+69 -0
variables:
example: this is an example variable
stages:
- stage1
- stage2
build:
stage: stage1
script:
- echo "We are currently in stage 1"
- echo "These are the contents of test.py"
- cat test.py
- echo $example
test:
stage: stage2
script:
- echo "We are currently in stage 2"
- echo "running python script"
- python3 test.py
- if [ $? -ne 0 ]; then
echo "Unit tests failed. Exiting pipeline.";
exit 1;
else
echo "Unit tests passed. Continuing to next stage.";
fi
File added
sum.py 0 → 100644
def add(a, b):
return a+b
\ No newline at end of file
test.py 0 → 100644
import unittest
import sum
import sys
class TestCalculator(unittest.TestCase):
def test_addition(self):
result = sum.add(2, 2)
self.assertEqual(result, 4)
def test_add_positive_and_negative_numbers(self):
result = sum.add(-2, 3)
self.assertEqual(result, 1)
def test_add_negative_numbers(self):
result = sum.add(-2, -3)
self.assertEqual(result, -5)
def test_add_zero(self):
result = sum.add(0, 5)
self.assertEqual(result, 5)
def test_add_large_numbers(self):
result = sum.add(123456789, 987654321)
self.assertEqual(result, 1111111110)
suite = unittest.TestLoader().loadTestsFromTestCase(TestCalculator)
result = unittest.TextTestRunner(verbosity=2).run(suite)
if result.wasSuccessful():
print("All tests passed!")
else:
print("Some tests failed.")
sys.exit(1)
if __name__ == '__main__':
unittest.main()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment