Advertisement
Guest User

Untitled

a guest
Aug 29th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. require 'rspec'
  2. require_relative 'base'
  3.  
  4. describe Base do
  5. describe '#smallest' do
  6. it do
  7. expect(subject.smallest('1')).to eq('base 2 => 1')
  8. end
  9.  
  10. it do
  11. expect(subject.smallest(21)).to eq('base 3 => 7')
  12. end
  13.  
  14. it do
  15. expect(subject.smallest('ab3')).to eq('base 12 => 1575')
  16. end
  17.  
  18. it do
  19. expect(subject.smallest('ff')).to eq('base 16 => 255')
  20. end
  21.  
  22. it do
  23. expect(subject.smallest(0)).to eq('base 1 => 0')
  24. end
  25. end
  26.  
  27. describe '#to_dec' do
  28. it do
  29. expect(subject.to_dec('66', 8)).to eq(54)
  30. end
  31.  
  32. it do
  33. expect(subject.to_dec(11011, 2)).to eq(27)
  34. end
  35.  
  36. it do
  37. expect(subject.to_dec('500', 10)).to eq(500)
  38. end
  39. end
  40.  
  41. describe '#all_bases' do
  42. it do
  43. expected = 'base 3 => 7
  44. base 4 => 9
  45. base 5 => 11
  46. base 6 => 13
  47. base 7 => 15
  48. base 8 => 17
  49. base 9 => 19
  50. base 10 => 21
  51. base 11 => 23
  52. base 12 => 25
  53. base 13 => 27
  54. base 14 => 29
  55. base 15 => 31
  56. base 16 => 33'
  57. expect(subject.all_bases(21)).to eq(expected)
  58. end
  59.  
  60. it do
  61. expected = 'base 1 => 0
  62. base 2 => 0
  63. base 3 => 0
  64. base 4 => 0
  65. base 5 => 0
  66. base 6 => 0
  67. base 7 => 0
  68. base 8 => 0
  69. base 9 => 0
  70. base 10 => 0
  71. base 11 => 0
  72. base 12 => 0
  73. base 13 => 0
  74. base 14 => 0
  75. base 15 => 0
  76. base 16 => 0'
  77. expect(subject.all_bases(0)).to eq(expected)
  78. end
  79. end
  80. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement