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

[Unit Tests] - senza-lnd.job.check_text_answer #44

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

[Unit Tests] - senza-lnd.job.check_text_answer #44

tomsmith8 opened this issue Nov 12, 2024 · 0 comments

Comments

@tomsmith8
Copy link
Owner

Unit Test Coverage for " senza-lnd.job.check_text_answer"


Stakwork Run


Unit Test Code


require 'rspec'
require 'ostruct'

# Assuming the function is defined within a module or class named Job
# and that the function is an instance method of a class that has
# `test_answer` and `user_answer` as attributes.

RSpec.describe 'Job#check_text_answer' do
before do
  # Mocking the Job class and its method
  @job = OpenStruct.new
  allow(@job).to receive(:check_text_answer).and_wrap_original do
    clean_test_answer = Job.strip_trailing_decimals_and_zeroes(@job.test_answer)
    clean_user_answer = Job.strip_trailing_decimals_and_zeroes(@job.user_answer)
    clean_test_answer.to_s == clean_user_answer.to_s
  end
end

it 'returns true for identical numeric strings' do
  @job.test_answer = "123.45"
  @job.user_answer = "123.45"
  expect(@job.check_text_answer).to be true
end

it 'returns true for identical numeric strings with trailing zeroes' do
  @job.test_answer = "123.4500"
  @job.user_answer = "123.45"
  expect(@job.check_text_answer).to be true
end

it 'returns true for identical numeric strings with trailing decimals' do
  @job.test_answer = "123.0"
  @job.user_answer = "123"
  expect(@job.check_text_answer).to be true
end

it 'returns true for empty strings' do
  @job.test_answer = ""
  @job.user_answer = ""
  expect(@job.check_text_answer).to be true
end

it 'returns true for zero values' do
  @job.test_answer = "0.0"
  @job.user_answer = "0"
  expect(@job.check_text_answer).to be true
end

it 'returns true for very large numbers' do
  @job.test_answer = "12345678901234567890.0"
  @job.user_answer = "12345678901234567890"
  expect(@job.check_text_answer).to be true
end

it 'returns true for identical non-numeric strings' do
  @job.test_answer = "abc"
  @job.user_answer = "abc"
  expect(@job.check_text_answer).to be true
end

it 'returns false for mismatched non-numeric strings' do
  @job.test_answer = "abc"
  @job.user_answer = "def"
  expect(@job.check_text_answer).to be false
end

it 'returns true for null values' do
  @job.test_answer = nil
  @job.user_answer = nil
  expect(@job.check_text_answer).to be true
end

it 'returns true for identical mixed numeric and non-numeric strings' do
  @job.test_answer = "123abc"
  @job.user_answer = "123abc"
  expect(@job.check_text_answer).to be true
end

it 'returns false for numeric and non-numeric mismatch' do
  @job.test_answer = "123abc"
  @job.user_answer = "123"
  expect(@job.check_text_answer).to be false
end

it 'returns true for very long numeric strings' do
  @job.test_answer = "1" * 1000 + ".0"
  @job.user_answer = "1" * 1000
  expect(@job.check_text_answer).to be true
end

it 'returns true for very long non-numeric strings' do
  @job.test_answer = "a" * 1000
  @job.user_answer = "a" * 1000
  expect(@job.check_text_answer).to be true
end

it 'returns false for different numeric values' do
  @job.test_answer = "123.45"
  @job.user_answer = "123.46"
  expect(@job.check_text_answer).to be false
end

it 'returns true for numeric strings with different formats' do
  @job.test_answer = "00123.4500"
  @job.user_answer = "123.45"
  expect(@job.check_text_answer).to be true
end

it 'returns true for whitespace handling' do
  @job.test_answer = " 123.45 "
  @job.user_answer = "123.45"
  expect(@job.check_text_answer).to be true
end

it 'returns true for leading and trailing whitespace' do
  @job.test_answer = "  123.4500  "
  @job.user_answer = "123.45"
  expect(@job.check_text_answer).to be true
end

it 'returns true for negative numbers' do
  @job.test_answer = "-123.0"
  @job.user_answer = "-123"
  expect(@job.check_text_answer).to be true
end

it 'returns true for scientific notation' do
  @job.test_answer = "1.23e2"
  @job.user_answer = "123"
  expect(@job.check_text_answer).to be true
end
end
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