Hopp til innhold

Modul:Coordinate/testtilfeller

Fra Wikipedia, den frie encyklopedi


local Coordinate = require('Module:Coordinate')
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()

function suite:testParseDecimalWithArcMilliSecondPrecision()
	local frame = self.frame
    local c = Coordinate:new(frame)
    s = c:parseDecimal(60.398545, 1/3600000)

    self:assertEquals(60, s.deg)
    self:assertEquals(23, s.min)
    self:assertEquals(54.762, s.sec)
end

function suite:testParseDecimalWithArcSecondPrecision()
	local frame = self.frame
    local c = Coordinate:new(frame)
    s = c:parseDecimal(60.398545, 1/3600)

    self:assertEquals(60, s.deg)
    self:assertEquals(23, s.min)
    self:assertEquals(55, s.sec)
end

function suite:testParseDecimalWithArcMinutePrecision()
	local frame = self.frame
    local c = Coordinate:new(frame)
    s = c:parseDecimal(60.398545, 1/60)

    self:assertEquals(60, s.deg)
    self:assertEquals(24, s.min)
    self:assertEquals(nil, s.sec)
end

function suite:testParseDecimalWithOneTenthDegreePrecision()
	local frame = self.frame
    local c = Coordinate:new(frame)
    s = c:parseDecimal(60.398545, 1/10)

    self:assertEquals(60, s.deg)
    self:assertEquals(24, s.min)
    self:assertEquals(nil, s.sec)
end

function suite:testParseDecimalWithDegreePrecision()
	local frame = self.frame
    local c = Coordinate:new(frame)
    s = c:parseDecimal(60.398545, 1)

    self:assertEquals(60, s.deg)
    self:assertEquals(nil, s.min)
    self:assertEquals(nil, s.sec)
end

function suite:testformatAsDmsNorth()
	local frame = self.frame
    local c = Coordinate:new(frame)
    res = c:formatAsDms({ deg = 69, min = 40, sec = nil, sign = 1 }, 'latitude')

    self:assertEquals("69°40′N", res)
end

function suite:testformatAsDmsSouth()
	local frame = self.frame
    local c = Coordinate:new(frame)
    res = c:formatAsDms({ deg = 69, min = 40, sec = nil, sign = -1 }, 'latitude')

    self:assertEquals("69°40′S", res)
end

function suite:testformatAsDmsWest()
	local frame = self.frame
    local c = Coordinate:new(frame)
    res = c:formatAsDms({ deg = 69, min = 40, sec = nil, sign = -1 }, 'longitude')

	self:assertEquals("69°40′V", res)
end

function suite:testformatAsDmsEast()
	local frame = self.frame
    local c = Coordinate:new(frame)
    res = c:formatAsDms({ deg = 69, min = 40, sec = nil, sign = 1 }, 'longitude')

    self:assertEquals("69°40′Ø", res)
end

function suite:testGeohackParams()
	local frame = self.frame
    local c = Coordinate:new(frame)
    res = c:geohackParams(
    	{ deg = 69, min = 40, sec = nil, sign = 1 }, 
    	{ deg = 18, min = 56, sec = nil, sign = 1 }
    )

    self:assertEquals("69_40_N_18_56_E", res)
end

return suite