utc_rpn_calc 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ - jruby-19mode # JRuby in 1.9 mode
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in utc_rpn_calc.gemspec
4
4
  gemspec
5
+
6
+ gem 'coveralls', require: false
data/README.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # UtcRpnCalc
2
2
 
3
- TODO: Write a gem description
3
+ [![Gem Version](https://badge.fury.io/rb/utc_rpn_calc.png)](http://badge.fury.io/rb/utc_rpn_calc)
4
+ [![Build Status](https://travis-ci.org/colinrymer/utc_rpn_calc.png?branch=master)](https://travis-ci.org/colinrymer/utc_rpn_calc)
5
+ [![Coverage Status](https://coveralls.io/repos/colinrymer/utc_rpn_calc/badge.png)](https://coveralls.io/r/colinrymer/utc_rpn_calc)
6
+ [![Code Climate](https://codeclimate.com/github/colinrymer/utc_rpn_calc.png)](https://codeclimate.com/github/colinrymer/utc_rpn_calc)
7
+ [![Dependency Status](https://gemnasium.com/colinrymer/utc_rpn_calc.png)](https://gemnasium.com/colinrymer/utc_rpn_calc)
8
+
9
+ A simple Reverse Polish Notation (RPN) hexadecimal calculator.
10
+ It was written as a demonstration of the UTC IEEE CS coding challenge
11
+ specifications for February 2014.
4
12
 
5
13
  ## Installation
6
14
 
@@ -18,11 +26,16 @@ Or install it yourself as:
18
26
 
19
27
  ## Usage
20
28
 
21
- TODO: Write usage instructions here
29
+ Pass a string of digits and operators separated with spaces as command line arguments, e.g.
30
+
31
+ ```
32
+ $ utc_rpn_calc 1 2 +
33
+ 0003
34
+ ```
22
35
 
23
36
  ## Contributing
24
37
 
25
- 1. Fork it ( http://github.com/<my-github-username>/utc_rpn_calc/fork )
38
+ 1. Fork it ( http://github.com/colinrymer/utc_rpn_calc/fork )
26
39
  2. Create your feature branch (`git checkout -b my-new-feature`)
27
40
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
41
  4. Push to the branch (`git push origin my-new-feature`)
data/bin/utc_rpn_calc ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), %w[.. lib])
4
+ require 'utc_rpn_calc'
5
+
6
+ input = ARGV.join(' ')
7
+
8
+ output = UtcRpnCalc::Calculator.new(input).calculate
9
+
10
+ print output
11
+
12
+ exit 1 if output == UtcRpnCalc::ERROR
@@ -1,10 +1,10 @@
1
1
  require 'utc_rpn_calc/core_ext/string'
2
2
  require 'utc_rpn_calc/core_ext/fixnum'
3
3
 
4
+ require 'utc_rpn_calc/error'
5
+
4
6
  module UtcRpnCalc
5
7
  class Calculator
6
-
7
- ERROR = "BLARGH!"
8
8
  FFFF = "FFFF".hex
9
9
 
10
10
  def initialize(input)
@@ -18,7 +18,7 @@ module UtcRpnCalc
18
18
  process_input(input)
19
19
  end
20
20
 
21
- @stack.pop.to_formatted_hex
21
+ calculated_value.to_formatted_hex
22
22
  end
23
23
 
24
24
  private
@@ -31,6 +31,10 @@ module UtcRpnCalc
31
31
  @stack.push(result(input))
32
32
  end
33
33
 
34
+ def calculated_value
35
+ @stack.pop || 0
36
+ end
37
+
34
38
  def result(input)
35
39
  input.valid_number? ? input.hex : compute(input)
36
40
  end
@@ -0,0 +1,3 @@
1
+ module UtcRpnCalc
2
+ ERROR = "BLARGH!"
3
+ end
@@ -1,3 +1,3 @@
1
1
  module UtcRpnCalc
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'utc_rpn_calc' do
4
+
5
+ describe 'exit codes' do
6
+
7
+ subject { `utc_rpn_calc #{input}`; $?.to_i }
8
+
9
+ describe 'zero exit code' do
10
+
11
+ context 'when no calculation' do
12
+ let(:input) { '' }
13
+ it { should eq(0) }
14
+ end
15
+
16
+ context 'when valid calculation' do
17
+ let(:input) { '1 2 +' }
18
+ it { should eq(0) }
19
+ end
20
+
21
+ end
22
+
23
+ describe 'non-zero exit code' do
24
+
25
+ context 'when invalid calculation' do
26
+ let(:input) { '1 + 2' }
27
+ it { should_not eq(0) }
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+
34
+ describe 'output' do
35
+
36
+ subject { `utc_rpn_calc #{input}` }
37
+
38
+ context 'when no calculation' do
39
+ let(:input) { '' }
40
+ it { should eq('0000') }
41
+ end
42
+
43
+ context 'when valid calculation' do
44
+ let(:input) { '1 2 +' }
45
+ it { should eq('0003') }
46
+ end
47
+
48
+ context 'when invalid calculation' do
49
+ let(:input) { '1 + 2' }
50
+ it { should eq(UtcRpnCalc::ERROR) }
51
+ end
52
+
53
+ end
54
+
55
+ end
File without changes
File without changes
File without changes
data/spec/spec_helper.rb CHANGED
@@ -5,6 +5,9 @@
5
5
  #
6
6
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
7
 
8
+ require 'coveralls'
9
+ Coveralls.wear!
10
+
8
11
  RSpec.configure do |config|
9
12
  config.treat_symbols_as_metadata_keys_with_true_values = true
10
13
  config.run_all_when_everything_filtered = true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utc_rpn_calc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-05 00:00:00.000000000 Z
12
+ date: 2014-02-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -62,24 +62,29 @@ dependencies:
62
62
  description: A simple RPN style calculator that operates on unsigned hex numbers
63
63
  email:
64
64
  - colin.rymer@gmail.com
65
- executables: []
65
+ executables:
66
+ - utc_rpn_calc
66
67
  extensions: []
67
68
  extra_rdoc_files: []
68
69
  files:
69
70
  - .gitignore
70
71
  - .rspec
72
+ - .travis.yml
71
73
  - Gemfile
72
74
  - LICENSE.txt
73
75
  - README.md
74
76
  - Rakefile
77
+ - bin/utc_rpn_calc
75
78
  - lib/utc_rpn_calc.rb
76
79
  - lib/utc_rpn_calc/calculator.rb
77
80
  - lib/utc_rpn_calc/core_ext/fixnum.rb
78
81
  - lib/utc_rpn_calc/core_ext/string.rb
82
+ - lib/utc_rpn_calc/error.rb
79
83
  - lib/utc_rpn_calc/version.rb
80
- - spec/calculator_spec.rb
81
- - spec/core_ext/fixnum_spec.rb
82
- - spec/core_ext/string_spec.rb
84
+ - spec/bin/utc_rpn_calc_spec.rb
85
+ - spec/lib/calculator_spec.rb
86
+ - spec/lib/core_ext/fixnum_spec.rb
87
+ - spec/lib/core_ext/string_spec.rb
83
88
  - spec/spec_helper.rb
84
89
  - utc_rpn_calc.gemspec
85
90
  homepage: https://github.com/colinrymer/utc_rpn_calc
@@ -97,7 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
102
  version: '0'
98
103
  segments:
99
104
  - 0
100
- hash: -4398044844294905452
105
+ hash: 92536587959642505
101
106
  required_rubygems_version: !ruby/object:Gem::Requirement
102
107
  none: false
103
108
  requirements:
@@ -106,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
111
  version: '0'
107
112
  segments:
108
113
  - 0
109
- hash: -4398044844294905452
114
+ hash: 92536587959642505
110
115
  requirements: []
111
116
  rubyforge_project:
112
117
  rubygems_version: 1.8.23
@@ -114,7 +119,8 @@ signing_key:
114
119
  specification_version: 3
115
120
  summary: A simple RPN style calculator that operates on unsigned hex numbers
116
121
  test_files:
117
- - spec/calculator_spec.rb
118
- - spec/core_ext/fixnum_spec.rb
119
- - spec/core_ext/string_spec.rb
122
+ - spec/bin/utc_rpn_calc_spec.rb
123
+ - spec/lib/calculator_spec.rb
124
+ - spec/lib/core_ext/fixnum_spec.rb
125
+ - spec/lib/core_ext/string_spec.rb
120
126
  - spec/spec_helper.rb