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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Tim Cooke
• Devaka Cooray
• Ron McLeod
• Jeanne Boyarsky
Sheriffs:
• Liutauras Vilda
• paul wheaton
• Junilu Lacar
Saloon Keepers:
• Tim Moores
• Stephan van Hulst
• Piet Souris
• Carey Brown
• Tim Holloway
Bartenders:
• Martijn Verburg
• Frits Walraven
• Himai Minh

# How to test below program using spock and groovy?

Greenhorn
Posts: 7
• Number of slices to send:
Optional 'thank-you' note:
public class RectFun {

public static void main(String[] args) {
RectangularShape rectangularShape
rectangularShape = new Rectangle2D.Double(10,20,30,50)
Rectangle2D rectangle = rotateRect(rectangularShape,30)
println(rectangle)
}
static Rectangle2D rotateRect (RectangularShape rect, int angle, Point2D  pivot = null )
{

if (pivot == null)
{
pivot = new Point2D.Double(rect.x + (int) Math.round(rect.width / 2d), rect.y + (int) Math.round(rect.height / 2d))
}

double rad = angle * Math.PI / 180;
double diffX = rect.x - pivot.x
double diffY = rect.y - pivot.y
int x = (int) Math.round(rect.x - diffX + (diffX * Math.cos(rad)) + (diffY * Math.sin(rad)))
int y = (int) Math.round(rect.y - diffY + (diffY * Math.cos(rad)) - (diffX * Math.sin(rad)))

return new Rectangle2D.Double(x, y, rect.width, rect.height)
}
}

Sheriff
Posts: 17357
300
• Number of slices to send:
Optional 'thank-you' note:
Have you searched for how to test with Spock and Groovy?

Narayanan Krish
Greenhorn
Posts: 7
• Number of slices to send:
Optional 'thank-you' note:

Junilu Lacar wrote:Have you searched for how to test with Spock and Groovy?

Yes , but could not get better idea on particular program.

Marshal
Posts: 76888
366
• Number of slices to send:
Optional 'thank-you' note:
Why do you insist on specifying the “how” (implementation)? Wouldn't it be better to work out what needs testing in yout application?