I have been debugging following class in Ruby over and over again trying to figure out what breaks it. I am out of ideas atm.
Funny enough this is a programming assignment for the course software testing at the university. We are to write a ruby program and determine some properties of a triangle. Note: not asking you guys to solve my problem form me, I think I am experiencing a possible bug in Ruby but more likely a mistake in my program. I am having a - so far - anomaly which i am unable to pinpoint to the use of some function/assignment/whatever.
To proof I am not using you to solve my programming task... This is the actual assignment: http://homepages.cwi.nl/~jve/courses/testing2009/week1/Lab1.pdf
Im having trouble with the triangle class I've been writing. Its the first time for me that Im writing a ruby program although Im familiar with VB6, C++ and C#. Usually I keep searching on google for the problem i am experiencing but I dont think i will find it there
Underneath I will post the working and the failing programs. Funny enough by taking out a function the program then works again even if the function is standalone. I have taken out random parts of the program and randomly put some back in. And as it appears the program seems to break at random. I am unable to find the culprit.
This might look long but its the same class over and over again. Just trying to show what I've tried so far. With "This doesnt work" I mean the fxri freezes.
PS. I've tried the same on my laptop too. And to be sure I DLd the latest version of Ruby
#This works
class Example
def initialize(a,b,c)
@pA = a
@pB = b
@pC = c
end
def shouldntThisWork()
myArray = [@pA,@pB,@pC]
end
def test()
arr1 = [@pA, @pB, @pC]
arr1.each { | elem | print elem, "\n"}
return
end
end
#This works
class Triangle
#checks first if inputs are of type float and bigger than zero
def initialize(sideA, sideB, sideC)
raise "Side A must be a float." if not sideA.kind_of? Float
raise "Side B must be a float." if not sideB.kind_of? Float
raise "Side C must be a float." if not sideC.kind_of? Float
raise "Size error for side A (must be greater than 0)" if sideA <= 0
raise "Size error for side B (must be greater than 0)" if sideB <= 0
raise "Size error for side C (must be greater than 0)" if sideC <= 0
@pA = sideA
@pB = sideB
@pC = sideC
end
def test()
arr1 = [@pA, @pB, @pC]
arr1.each { | elem | print elem, "\n"}
return
end
end
#This works
class Triangle
#checks first if inputs are of type float and bigger than zero
def initialize(sideA, sideB, sideC)
raise "Side A must be a float." if not sideA.kind_of? Float
raise "Side B must be a float." if not sideB.kind_of? Float
raise "Side C must be a float." if not sideC.kind_of? Float
raise "Size error for side A (must be greater than 0)" if sideA <= 0
raise "Size error for side B (must be greater than 0)" if sideB <= 0
raise "Size error for side C (must be greater than 0)" if sideC <= 0
@pA = sideA
@pB = sideB
@pC = sideC
end
def isEquilateral()
return (@pA == @pB and @pB == @pC)
end
def isIsosceles()
numEqual = 0
if @pA == @pB
numEqual += 1
end
if @pA == @pC
numEqual += 1
end
if @pC == @pB
numEqual += 1
end
return (numEqual == 2)
end
def test()
arr1 = [@pA, @pB, @pC]
arr1.each { | elem | print elem, "\n"}
return
end
end
# This Works
class Triangle
#checks first if inputs are of type float and bigger than zero
def initialize(sideA, sideB, sideC)
raise "Side A must be a float." if not sideA.kind_of? Float
raise "Side B must be a float." if not sideB.kind_of? Float
raise "Side C must be a float." if not sideC.kind_of? Float
raise "Size error for side A (must be greater than 0)" if sideA <= 0
raise "Size error for side B (must be greater than 0)" if sideB <= 0
raise "Size error for side C (must be greater than 0)" if sideC <= 0
@pA = sideA
@pB = sideB
@pC = sideC
end
def isEquilateral()
return (@pA == @pB and @pB == @pC)
end
def isIsosceles()
numEqual = 0
if @pA == @pB
numEqual += 1
end
if @pA == @pC
numEqual += 1
end
if @pC == @pB
numEqual += 1
end
return (numEqual == 2)
end
def test()
arr1 = [@pA, @pB, @pC]
arr1.each { | elem | print elem, "\n"}
return
end
end
#This works
class Triangle
#checks first if inputs are of type float and bigger than zero
def initialize(sideA, sideB, sideC)
raise "Side A must be a float." if not sideA.kind_of? Float
raise "Side B must be a float." if not sideB.kind_of? Float
raise "Side C must be a float." if not sideC.kind_of? Float
raise "Size error for side A (must be greater than 0)" if sideA <= 0
raise "Size error for side B (must be greater than 0)" if sideB <= 0
raise "Size error for side C (must be greater than 0)" if sideC <= 0
@pA = sideA
@pB = sideB
@pC = sideC
end
def A()
return @pA
end
def B()
return @pB
end
def C()
return @pC
end
def test()
arr1 = [@pA, @pB, @pC]
arr1.each { | elem | print elem, "\n"}
return
end
def isEquilateral()
return (@pA == @pB and @pB == @pC)
end
end
# this doesnt work
class Triangle
#checks first if inputs are of type float and bigger than zero
def initialize(sideA, sideB, sideC)
raise "Side A must be a float." if not sideA.kind_of? Float
raise "Side B must be a float." if not sideB.kind_of? Float
raise "Side C must be a float." if not sideC.kind_of? Float
raise "Size error for side A (must be greater than 0)" if sideA <= 0
raise "Size error for side B (must be greater than 0)" if sideB <= 0
raise "Size error for side C (must be greater than 0)" if sideC <= 0
@pA = sideA
@pB = sideB
@pC = sideC
end
def A()
return @pA
end
def B()
return @pB
end
def C()
return @pC
end
def test()
arr1 = [@pA, @pB, @pC]
arr1.each { | elem | print elem, "\n"}
return
end
def isEquilateral()
return (@pA == @pB and @pB == @pC)
end
def isIsosceles()
numEqual = 0
if @pA == @pB
numEqual += 1
end
if @pA == @pC
numEqual += 1
end
if @pC == @pB
numEqual += 1
end
return (numEqual == 2)
end
end
# But then this does work
class Triangle
#checks first if inputs are of type float and bigger than zero
def initialize(sideA, sideB, sideC)
raise "Side A must be a float." if not sideA.kind_of? Float
raise "Side B must be a float." if not sideB.kind_of? Float
raise "Side C must be a float." if not sideC.kind_of? Float
raise "Size error for side A (must be greater than 0)" if sideA <= 0
raise "Size error for side B (must be greater than 0)" if sideB <= 0
raise "Size error for side C (must be greater than 0)" if sideC <= 0
@pA = sideA
@pB = sideB
@pC = sideC
end
def A()
return @pA
end
def B()
return @pB
end
def C()
return @pC
end
def isEquilateral()
return (@pA == @pB and @pB == @pC)
end
def isIsosceles()
numEqual = 0
if @pA == @pB
numEqual += 1
end
if @pA == @pC
numEqual += 1
end
if @pC == @pB
numEqual += 1
end
return (numEqual == 2)
end
end
# This doesnt
class Triangle
#checks first if inputs are of type float and bigger than zero
def initialize(sideA, sideB, sideC)
raise "Side A must be a float." if not sideA.kind_of? Float
raise "Side B must be a float." if not sideB.kind_of? Float
raise "Side C must be a float." if not sideC.kind_of? Float
raise "Size error for side A (must be greater than 0)" if sideA <= 0
raise "Size error for side B (must be greater than 0)" if sideB <= 0
raise "Size error for side C (must be greater than 0)" if sideC <= 0
@pA = sideA
@pB = sideB
@pC = sideC
end
def A()
return @pA
end
def B()
return @pB
end
def C()
return @pC
end
def isEquilateral()
return (@pA == @pB and @pB == @pC)
end
def isIsosceles()
numEqual = 0
if @pA == @pB
numEqual += 1
end
if @pA == @pC
numEqual += 1
end
if @pC == @pB
numEqual += 1
end
return (numEqual == 2)
end
def test()
arr1 = [@pA, @pB, @pC]
arr1.each { | elem | print elem, "\n"}
return
end
end
# This works again
class Triangle
#checks first if inputs are of type float and bigger than zero
def initialize(sideA, sideB, sideC)
@pA = sideA
@pB = sideB
@pC = sideC
end
def A()
return @pA
end
def B()
return @pB
end
def C()
return @pC
end
def isEquilateral()
return (@pA == @pB and @pB == @pC)
end
def isIsosceles()
numEqual = 0
if @pA == @pB
numEqual += 1
end
if @pA == @pC
numEqual += 1
end
if @pC == @pB
numEqual += 1
end
return (numEqual == 2)
end
def test()
arr1 = [@pA, @pB, @pC]
arr1.each { | elem | print elem, "\n"}
return
end
end
#test
class Triangle
#checks first if inputs are of type float and bigger than zero
def initialize(sideA, sideB, sideC)
@pA = sideA
@pB = sideB
@pC = sideC
end
def A()
return @pA
end
def B()
return @pB
end
def C()
return @pC
end
def isEquilateral()
return (@pA == @pB and @pB == @pC)
end
def isIsosceles()
numEqual = 0
if @pA == @pB
numEqual += 1
end
if @pA == @pC
numEqual += 1
end
if @pC == @pB
numEqual += 1
end
return (numEqual == 2)
end
def test()
arr1 = [@pA, @pB, @pC]
arr1.each { | elem | print elem, "\n"}
return
end
def dunno()
return "Dunno"
end
def neee()
return "Een ", @pA
end
end