|
| 1 | +require "rspec/autorun" |
| 2 | +require_relative './helper' |
| 3 | +RSpec.describe "CalculationTest" do |
| 4 | + |
| 5 | + it "is_valid_hex_with_valid_hex" do |
| 6 | + result=is_valid_hex('f06830ca9f1e3e90') |
| 7 | + expect(true).to eq(result) |
| 8 | + end |
| 9 | + |
| 10 | + it "is_valid_hex_with_invalid_hex" do |
| 11 | + result=is_valid_hex('f06830ca9f1e3e90$') |
| 12 | + expect(false).to eq(result) |
| 13 | + end |
| 14 | + |
| 15 | + it "hamming_distance_test_expect_0" do |
| 16 | + result=hamming_distance('f06830ca9f1e3e90','f06830ca9f1e3e90') |
| 17 | + expect(0).to eq(result) |
| 18 | + end |
| 19 | + |
| 20 | + it "hamming_distance_test_expect_17" do |
| 21 | + result=hamming_distance('2d5ad3936d2e015b','2d6ed293db36a4fb') |
| 22 | + expect(17).to eq(result) |
| 23 | + end |
| 24 | + |
| 25 | + it "hamming_distance_test_expect_37" do |
| 26 | + result=hamming_distance('a4a65595ac94518b','7838873e791f8400') |
| 27 | + expect(37).to eq(result) |
| 28 | + end |
| 29 | + |
| 30 | + it "get_authenticated_params_test_with_nil_expire_nill_token" do |
| 31 | + allow(OpenSSL::HMAC).to receive(:hexdigest).and_return('my_signature') |
| 32 | + result=get_authenticated_params(nil,nil,'private_key') |
| 33 | + expect(nil).not_to eq(result[:token]) |
| 34 | + expect(nil).not_to eq(result[:expire]) |
| 35 | + expect('my_signature').to eq(result[:signature]) |
| 36 | + end |
| 37 | + |
| 38 | + it "get_authenticated_params_test_with_nil_expire" do |
| 39 | + allow(OpenSSL::HMAC).to receive(:hexdigest).and_return('my_signature') |
| 40 | + result=get_authenticated_params('my_token',nil,'private_key') |
| 41 | + expect('my_token').to eq(result[:token]) |
| 42 | + expect(nil).not_to eq(result[:expire]) |
| 43 | + expect('my_signature').to eq(result[:signature]) |
| 44 | + end |
| 45 | + |
| 46 | + it "get_authenticated_params_test_with_hard_coded_params" do |
| 47 | + result=get_authenticated_params('your_token',1582269249,'private_key_test') |
| 48 | + expect('your_token').to eq(result[:token]) |
| 49 | + expect(nil).not_to eq(result[:expire]) |
| 50 | + expect('e71bcd6031016b060d349d212e23e85c791decdd').to eq(result[:signature]) |
| 51 | + end |
| 52 | + |
| 53 | + it "get_authenticated_params_test_with_nil_token" do |
| 54 | + allow(OpenSSL::HMAC).to receive(:hexdigest).and_return('my_signature') |
| 55 | + result=get_authenticated_params(nil,nil,'private_key') |
| 56 | + expect(nil).not_to eq(result[:token]) |
| 57 | + expect(nil).not_to eq(result[:expire]) |
| 58 | + expect('my_signature').to eq(result[:signature]) |
| 59 | + end |
| 60 | +end |
0 commit comments