Browse files

Return nil for numbers that won't have primes

  • Loading branch information...
1 parent 4d448cd commit 3cd7117abe73cf27f2a570861a65d68377670ce6 @joshuaclayton committed Aug 29, 2010
Showing with 3 additions and 5 deletions.
  1. +1 −1 ext/sieve/sieve.c
  2. +2 −2 features/sieve.feature
  3. +0 −2 features/step_definitions/sieve_steps.rb
View
2 ext/sieve/sieve.c
@@ -10,7 +10,7 @@ void Init_sieve() {
}
static VALUE sieve(const VALUE self) {
- if(NUM2LONG(self) < 0) { return Qnil; }
+ if(NUM2LONG(self) < 2) { return Qnil; }
long number = NUM2LONG(self) + 1,
* numbers = malloc(number * sizeof(long));
View
4 features/sieve.feature
@@ -11,8 +11,8 @@ Feature: Sieve of Eratosthenes
| -12345 | nil |
| -5 | nil |
| -1 | nil |
- | 0 | |
- | 1 | |
+ | 0 | nil |
+ | 1 | nil |
| 2 | 2 |
| 3 | 2,3 |
| 4 | 2,3 |
View
2 features/step_definitions/sieve_steps.rb
@@ -9,8 +9,6 @@
case primes
when "nil"
@result.should be_nil
- when ""
- @result.should be_empty
else
@primes = primes.split(",").map {|prime| prime.to_i }
@result.should == @primes

0 comments on commit 3cd7117

Please sign in to comment.