primetable 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae2aa3d6779044cdd1d19943acdd0a3e6e01ff9a
4
- data.tar.gz: 182c03f1034484cb7e763f72a9f42ec674544847
3
+ metadata.gz: 566ac4a8fea09057f10c6a0de3a8fe8e3e777f4d
4
+ data.tar.gz: 51efa22f323ae8bd1adf0c1c050e2f3533a241e0
5
5
  SHA512:
6
- metadata.gz: a9223cd8283e1595f9f7ee75ccaeb0dcad8908879cb083df062667898793634bee90ec736ea48d3bd6f34b73f5f418922ce8f6579441ccf3febafe9afd839632
7
- data.tar.gz: e9f6e1c7575be3ad6d7e0515d2b2cb687337cb892c5e80a2da49485cbbeeee903b0145d8964b7ce1965b8be71987faad56aeb9b8d0a39e00ba1681e0ec4e8a01
6
+ metadata.gz: 8699d55cc6edf5fc7f62a84ac132ca57c79d1f08bdb0d7726a2bcd3af4ff41d068a2ff8089be24541814feaa930b84434d8eed618bc08497a3146b998a1da4a0
7
+ data.tar.gz: 6df357240c68bbbbdc1214e328b7dd75c5c99855c1ee54c2a2ca1bcef90fa988863b35e3e813736dac32cb88b2d0c6b3ef4659e80cb9038a43a6ed6bbf3bab69
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- primetable (1.1.0)
4
+ primetable (1.1.2)
5
5
  formatador (~> 0.2, >= 0.2.5)
6
6
  therubyracer (~> 0.12, >= 0.12.2)
7
7
 
data/js/prime.js CHANGED
@@ -1,3 +1,8 @@
1
+ // LIBPRIME
2
+ // Script: prime.js
3
+ // Author: Day Davis Waterbury
4
+ // License: MIT (../LICENSE.txt)
5
+
1
6
  var factors = [];
2
7
  var primes = [];
3
8
 
@@ -20,7 +25,7 @@ function libPrime(method, n, count) {
20
25
  }
21
26
  return primes;
22
27
  }
23
- // console.log("* n:"+n);
28
+
24
29
  // We don't care about divisibility by 1, so we begin at 2
25
30
  var divisor = 2;
26
31
 
@@ -77,10 +82,3 @@ function primeFactors(n) {
77
82
  function generatePrimes(n,count) {
78
83
  return libPrime("generatePrimes",n, count);
79
84
  }
80
- // Try it out
81
- // // console.log(isPrime(1));
82
- // console.log(generatePrimes(1999867));
83
- // Try it out
84
- // for (var i = 1; i < 1002; i++) {
85
- // // console.log(i + " is " + (isPrime(i) ? "PRIME" : "COMPOSITE") + (!(isPrime(i)) ? (": " + primeFactors(i)) : ""));
86
- // }
data/lib/primetable.rb CHANGED
@@ -131,7 +131,7 @@ class PrimeTable
131
131
  # Here we read in the file one line at a time. Yes I looked for a faster way. Try :fast (-f).
132
132
  # 1) We don't want to slurp the whole file...what if the file was even larger? Not cool.
133
133
  # 2) IO.readlines gets the file one line at a time, so we need a line number, not an index.
134
- IO.readlines("data/prime.dat").each_with_index{|line,ln|
134
+ IO.readlines("#{ROOT_DIR}/data/prime.dat").each_with_index{|line,ln|
135
135
 
136
136
  # When we find the lines we want, we concatenate them into a single array. We get extra.
137
137
  if (ln >= first_line and ln <= last_line)
@@ -152,8 +152,8 @@ class PrimeTable
152
152
  # One nice thing about this is that I can easily set a timeout, so if someone asks us to run
153
153
  # some astronomical prime, we won't seize up the CPU forever. 7000ms is arbitrary.
154
154
  calc_primes_js = V8::Context.new timeout: 7000
155
- File.open("js/prime.js") do |file|
156
- calc_primes_js.eval(file, "#{ROOT_DIR}/js/prime.js")
155
+ File.open("#{ROOT_DIR}/js/prime.js") do |file|
156
+ calc_primes_js.eval(file)
157
157
  end
158
158
  primes_js = calc_primes_js.eval("generatePrimes(#{first},#{count})")
159
159
  YAML::load("[#{primes_js}]")
@@ -1,3 +1,3 @@
1
1
  class PrimeTable
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
@@ -81,9 +81,18 @@ Common options:
81
81
  expect(PrimeTable::VERSION).not_to be nil
82
82
  end
83
83
 
84
+ it "can access the JS script for generating primes" do
85
+ expect(`head -n 1 #{ROOT_DIR}/js/prime.js`).to eq "// LIBPRIME\n"
86
+ end
87
+
88
+ it "can access the data file for pre-calculated primes" do
89
+ expect(`head -n 1 #{ROOT_DIR}/data/prime.dat`).to eq "[2,3,5,7,11,13,17,19,23,29]\n"
90
+ end
91
+
84
92
  it 'executes when called on the command line' do
85
93
  expect(`primetable`).to include("PrimeTable is running...\n")
86
94
  end
95
+
87
96
  it 'executes *and* prints out a run time when passed -t or --time' do
88
97
  execution_output = `primetable -t`
89
98
  expect(execution_output).to include(@expected_execution_output)
@@ -91,22 +100,36 @@ Common options:
91
100
  execution_output = `primetable --time`
92
101
  expect(execution_output).to include(@expected_execution_output)
93
102
  expect(execution_output).to include(@expected_time_output)
94
- end
103
+ end
104
+
95
105
  it 'prints out the version number when passed -v or --version' do
96
- expect(`primetable -v`).to include(@expected_version_output)
106
+ execution_output = `primetable -v`
107
+ expect(execution_output).to include(@expected_version_output)
108
+ execution_output = `primetable --version`
109
+ expect(execution_output).to include(@expected_version_output)
110
+ end
111
+
112
+ it 'it does *not* generate a table when called with *only* -v or --version' do
113
+ execution_output = `primetable -v`
114
+ expect(execution_output).not_to include(@expected_table_display_first_ten)
115
+ execution_output = `primetable --version`
116
+ expect(execution_output).not_to include(@expected_table_display_first_ten)
97
117
  end
118
+
98
119
  it 'executes *and* prints out a run time *and* prints out the version number when passed both -t and -v arguments' do
99
120
  execution_output = `primetable -tv`
100
121
  expect(execution_output).to include(@expected_execution_output)
101
122
  expect(execution_output).to include(@expected_time_output)
102
123
  expect(execution_output).to include(@expected_version_output)
103
124
  end
125
+
104
126
  it 'executes *and* prints out a run time *and* prints out the version number when passed both --time and --version arguments' do
105
127
  execution_output = `primetable --time --version`
106
128
  expect(execution_output).to include(@expected_execution_output)
107
129
  expect(execution_output).to include(@expected_time_output)
108
130
  expect(execution_output).to include(@expected_version_output)
109
131
  end
132
+
110
133
  it 'prints out usage details when passed -h or --help' do
111
134
  execution_output = `primetable -h`
112
135
  expect(execution_output).to include(@expected_help_output)
@@ -114,16 +137,25 @@ Common options:
114
137
  expect(execution_output).to include(@expected_help_output)
115
138
  end
116
139
 
140
+ it 'it does *not* generate a table when called with *only* -h or --help' do
141
+ execution_output = `primetable -h`
142
+ expect(execution_output).not_to include(@expected_table_display_first_ten)
143
+ execution_output = `primetable --help`
144
+ expect(execution_output).not_to include(@expected_table_display_first_ten)
145
+ end
146
+
117
147
  it "has the right data when we run it with :load" do
118
148
  test_instance = PrimeTable.new(2,10,:load,true)
119
149
  expect(test_instance.primes).to eq(@expected_first_ten_primes)
120
150
  expect(test_instance.table).to eq(@expected_table_with_first_ten_primes)
121
151
  end
152
+
122
153
  it "has the right data when we run it with :fast" do
123
154
  test_instance = PrimeTable.new(2,10,:fast,true)
124
155
  expect(test_instance.primes).to eq(@expected_first_ten_primes)
125
156
  expect(test_instance.table).to eq(@expected_table_with_first_ten_primes)
126
157
  end
158
+
127
159
  it "has the right data when we run it with :calc" do
128
160
  test_instance = PrimeTable.new(2,10,:calc,true)
129
161
  expect(test_instance.primes).to eq(@expected_first_ten_primes)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: primetable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Day Davis Waterbury