Ugrás a tartalomhoz

Modul:Coordinate/tests

A Wikipédiából, a szabad enciklopédiából
A lap korábbi változatát látod, amilyen JulesWinnfield-hu (vitalap | szerkesztései) 2013. december 14., 23:03-kor történt szerkesztése után volt. Ez a változat jelentősen eltérhet az aktuális változattól.

Coordinate modul tesztek[mi ez?]

Név Várt Tényleges
Igen testCreate
testFromString 49,621667, 16,871528 49,621666666667, 16,871527777778
Igen testEquals
Igen testNew
testFormat 47.621667, 16.871528 L, l
local Coordinate = require('Modul:Coordinate')
local ScribuntoUnit = require('Modul:ScribuntoUnit')
local suite = ScribuntoUnit:new()

function suite:testCreate()
    local lat, long = 47.498056, 19.038056
    local coord = Coordinate.create(lat, long)
    self:assertEquals(Coordinate, getmetatable(coord))
    self:assertEquals(lat, coord.latitude)
    self:assertEquals(long, coord.longitude)
end

function suite:testNew()
    local lat, long = 47.498056, 19.038056
    local coord = Coordinate:new{latitude = lat, longitude = long}
    self:assertEquals(Coordinate, getmetatable(coord))
    self:assertEquals(lat, coord.latitude)
    self:assertEquals(long, coord.longitude)
end

function suite:testEquals()
    local lat, long = 47.498056, 19.038056
    local coord1 = Coordinate:new{latitude = lat, longitude = long}
    local coord2 = Coordinate:new{latitude = lat, longitude = long}
    self:assertTrue(coord1 == coord2)
end

function suite:testFormat()
    local lat, long = 47.621667, 16.871528
    local coord = Coordinate:new{latitude = lat, longitude = long}
    self:assertEquals('47.621667, 16.871528', coord:format('L, l'))
    self:assertEquals('É 47.621667°, K 16.871528°', coord:format('I L°, i l°'))
    self:assertEquals('47° 37′ 18″ N, 16° 52′ 17.5″ E', coord:format('D° M′ S″ C, d° m′ s″ c'))
end

function suite:testFromString()
    local coord1 = Coordinate:new{latitude = 47.621667, longitude = 16.871528}
    local coord2 = Coordinate:new{latitude = 48.621667, longitude = 16.871528}
    local coord3 = Coordinate:new{latitude = 49.621667, longitude = 16.871528}
    
    self:assertEquals(coord1, Coordinate.fromString('47.621667, 16.871528'))
    self:assertEquals(coord2, Coordinate.fromString('É 48,621667, K 16,871528'))
    self:assertEquals(coord3, Coordinate.fromString('49° 37′ 18″ N, 16° 52′ 17.5″ E'):__tostring())
end

return suite