0

I am trying to write some test cases using HUnit in Haskell for a function using the Gloss Graphics library.

The function:

makePicture :: Color -> Picture
makePicture c = Color c $ Circle 80

If I display a call to this function with argument "black" in a console you see something like:

Color (RGBA 0.0 0.0 0.0 1.0) (Circle 80.0)

Which has the type of a Picture. My question is how do I properly write a test case for something like this?

The problem occurs if I try to write a test like:

test = TestCase $ assertEqual "makePicture" (Color (RGBA 0.0 0.0 0.0 1.0) (Circle 80.0)) (makePicture black)

It can't compile, because it says the following:

error: Data constructor not in scope: RGBA

Anyone have any ideas how I can write a test case for my function?

user5846939
  • 415
  • 4
  • 11

1 Answers1

2

I don't know where you are getting the RGBA constructor, but looking at the haddocks there is no such constructor for a Color. You probably want the makeColor function:

makeColor :: Float -> Float -> Float -> Float -> Color

EDIT: And yes, user24...38 is right there exists an RGBA but in the version of Gloss I'm looking at it is part of an Internal module and not exported elsewhere. As a general rule, external users should not leverage Internal modules since the API might change or the interface can be somehow unsafe (ex: not maintaining invariants).

Thomas M. DuBuisson
  • 64,245
  • 7
  • 109
  • 166
  • [There is such a constructor](https://hackage.haskell.org/package/gloss-rendering-1.10.3.5/docs/src/Graphics-Gloss-Internals-Data-Color.html#Color), it is defined in a dependency of gloss, but `Color` is abstract and the constructor is not exported. Effectively, 'there is no such constructor' is a true statement, but perhaps this pedantic distinction would be useful to the understanding for someone. – user2407038 Mar 01 '17 at 17:10