This week's book giveaway is in the NodeJS forum.
We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line!
See this thread for details.
Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Fibonacci Sequence  RSS feed

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have written code below which does the Fibonacci Sequence the problem I am having is that when I run it against my JUnit Test code only one problem is resolved. I will show you below.

This is my glorious code.....not really.


Now this is my Unit Test code


When I run it against this only one issue is resolved, if anybody can tell me what i am doing wrong it will be greatly appreciated.
Capture.PNG
[Thumbnail for Capture.PNG]
JUnit Failure
 
Sheriff
Posts: 21692
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are three very clear errors in your code:

1) You always set the position argument to 10, so no matter what Fibonacci number you want, you would always get the same value (for position 10).
2) Your loop body always does the exact same thing. It doesn't use the loop counter, but always does the same thing, regardless of the input.
3) You always return 0.

You need to step away from a computer, and write down on paper how you would do this first.
 
Kaid Elliott
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Spoor wrote:There are three very clear errors in your code:

1) You always set the position argument to 10, so no matter what Fibonacci number you want, you would always get the same value (for position 10).
2) Your loop body always does the exact same thing. It doesn't use the loop counter, but always does the same thing, regardless of the input.
3) You always return 0.

You need to step away from a computer, and write down on paper how you would do this first.



Not to be disrespectful in any way but I wouldn't have asked if I did not already write this down on paper, search on google or read about it, can you explain with code I'm not asking you to do the work simply modify my code. I have Changed position to = 0. by the way and it and still does the same thing
 
Sheriff
Posts: 24295
55
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Kaid Elliott wrote:can you explain with code I'm not asking you to do the work simply modify my code.



There's very little difference between the two. The "work" you need to do here is to simply modify your code.

However let me ask you this. You've got a for-loop between lines 11 and 21. Rob already mentioned this, but I'll put it another way. That loop has a loop counter. What is it supposed to do and why don't you need to use it anywhere in the loop?

And then, as Rob pointed out: your Fib_No method is supposed to return an integer value. Presumably that value is supposed to depend on the "position" parameter in some way? You should be able to explain that, I expect it's described in the problem statement. Your code always returns zero, which I'm sure must be wrong.

And no, you can't expect to fix that code by asking Mr. Google. Look at this example, unrelated to yours:



You might find out through testing that the method doesn't always return the sum of a and b, but no amount of web searching is going to point out the obvious error.
 
Marshal
Posts: 63843
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You also appear to have an out by one error. You are showing Fibonacci numbers 1 2 3 4 8 14. That might be correct for a Fibonacci sequence starting 1 2, but the common Fibonacci sequence starts 1 1; it continues 1 1 2 3 5 8 13 21 34 55..., and fib₁₀ = 55.
No, your result doesn't seem to be correct for a sequence starting 1 2.
 
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!