Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: Test #42

Open
tomsmith8 opened this issue Nov 12, 2024 · 0 comments
Open

Test: Test #42

tomsmith8 opened this issue Nov 12, 2024 · 0 comments

Comments

@tomsmith8
Copy link
Owner

Coverage for: Test


Stakwork Run


Unit Test Code


import unittest

# Mock implementation of the Job class and its method
class Job:
  def __init__(self, test_answer, user_answer):
      self.test_answer = test_answer
      self.user_answer = user_answer

  @staticmethod
  def strip_trailing_decimals_and_zeroes(value):
      if value is None:
          return None
      if isinstance(value, (int, float)):
          value = str(value)
      if not isinstance(value, str):
          return value
      value = value.strip()
      if '.' in value:
          value = value.rstrip('0').rstrip('.')
      return value

  def check_text_answer(self):
      clean_test_answer = Job.strip_trailing_decimals_and_zeroes(self.test_answer)
      clean_user_answer = Job.strip_trailing_decimals_and_zeroes(self.user_answer)
      return clean_test_answer == clean_user_answer

class TestCheckTextAnswer(unittest.TestCase):

  def test_identical_numeric_strings(self):
      job = Job("123.4500", "123.45")
      self.assertTrue(job.check_text_answer())

  def test_identical_non_numeric_strings(self):
      job = Job("hello", "hello")
      self.assertTrue(job.check_text_answer())

  def test_different_numeric_strings(self):
      job = Job("123.45", "123.46")
      self.assertFalse(job.check_text_answer())

  def test_different_non_numeric_strings(self):
      job = Job("hello", "world")
      self.assertFalse(job.check_text_answer())

  def test_trailing_zeroes_in_user_answer(self):
      job = Job("100", "100.000")
      self.assertTrue(job.check_text_answer())

  def test_trailing_zeroes_in_test_answer(self):
      job = Job("100.000", "100")
      self.assertTrue(job.check_text_answer())

  def test_empty_strings(self):
      job = Job("", "")
      self.assertTrue(job.check_text_answer())

  def test_one_empty_string(self):
      job = Job("0", "")
      self.assertFalse(job.check_text_answer())

  def test_null_values(self):
      job = Job(None, "123")
      self.assertFalse(job.check_text_answer())

  def test_invalid_data_types(self):
      job = Job(123, "123")
      self.assertTrue(job.check_text_answer())

  def test_non_string_inputs(self):
      job = Job([1, 2, 3], "123")
      self.assertFalse(job.check_text_answer())

  def test_very_large_numeric_strings(self):
      job = Job("1" + "0" * 1000, "1" + "0" * 1000)
      self.assertTrue(job.check_text_answer())

  def test_very_large_non_numeric_strings(self):
      job = Job("a" * 1000, "a" * 1000)
      self.assertTrue(job.check_text_answer())

  def test_scientific_notation(self):
      job = Job("1e3", "1000")
      self.assertFalse(job.check_text_answer())  # Assuming no scientific notation handling

  def test_leading_zeroes(self):
      job = Job("00123", "123")
      self.assertTrue(job.check_text_answer())

  def test_whitespace_handling(self):
      job = Job(" 123 ", "123")
      self.assertTrue(job.check_text_answer())

  def test_mixed_numeric_and_non_numeric_strings(self):
      job = Job("abc123", "abc123")
      self.assertTrue(job.check_text_answer())

  def test_different_mixed_numeric_and_non_numeric_strings(self):
      job = Job("abc123", "abc124")
      self.assertFalse(job.check_text_answer())

  def test_whitespace_and_trailing_zeroes(self):
      job = Job(" 100.000 ", "100")
      self.assertTrue(job.check_text_answer())

if __name__ == '__main__':
  unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant