###############################################################################
# File:        UnitTest_StarDust.py
# Appointment: GUI unittest star dust 
# Project:     GalaxyU
# Author:      AR
# History:
# 30.10.2013 Created
###############################################################################
import unittest
import sys
sys.path.append("../")
import guStarDust
import zx

###############################################################################
class TestStarDust(unittest.TestCase):
    def setUp(self):
        pass

    #--------------------------------------------------------------------------
    def test_star_dust_point(self):
        sd = guStarDust.CStarDust(1,2, (1,2,3))
        self.assertEqual(1, sd.X);
        self.assertEqual(2, sd.Y);
        self.assertEqual((1,2,3), sd.Colour);

    #--------------------------------------------------------------------------
    def test_star_dust_generation(self):
        area = zx.CArea(0,0, 100, 100)
        sdlist = guStarDust.Generate(100, area)
        self.assertEqual(100, len(sdlist))
        for sd in sdlist:
            self.assertTrue(sd.X >= area.GetLeft() and sd.X <= area.GetRight() and sd.Y >= area.GetTop() and sd.Y <= area.GetBottom())


    #--------------------------------------------------------------------------
    def test_star_dust_generation_with_func(self):
        area = zx.CArea(31,11,123,156)
        anotherList = [] # list to be filled by passed function
        sdlist = guStarDust.Generate(78, area,
                                     lambda sd: anotherList.append(sd))
        self.assertEqual(78, len(sdlist))
        
        # check another list is the same as generated list
        self.assertEqual(len(anotherList), len(sdlist))
        for i in range(0, len(sdlist)):
            self.assertEqual(anotherList[i], sdlist[i])
        self.assertEqual(sdlist, anotherList)

        # check coordinates
        for sd in sdlist:
            self.assertTrue(sd.X >= area.GetLeft() and sd.X <= area.GetRight() and sd.Y >= area.GetTop() and sd.Y <= area.GetBottom())

################################################################################
if __name__ == "__main__":
    unittest.main()
