Ugrás a tartalomhoz

Modul:Coordinate/tests

Ellenőrzött
A Wikipédiából, a szabad enciklopédiából

Coordinate modul tesztek[mi ez?]

Név Várt Tényleges
Igen testFromString
Igen testEquals
Igen testFormat
Igen testCreate
Igen testDms
Igen testDetectPrecision
Igen testValidateDms
Igen testNew
Igen testCoord
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)
    self:assertEquals(nil, Coordinate:new{latitude = 47, longitude = 400})
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'))
    self:assertEquals(nil, Coordinate.fromString('47, 400'))
end

function suite:testDetectPrecision()
	self:assertEquals(Coordinate.PRECISION.D, Coordinate:new{latitude = 1, longitude = 0}.precision)
	self:assertEquals(Coordinate.PRECISION.M, Coordinate:new{latitude = 1 + 7 / 60, longitude = 0}.precision)
	self:assertEquals(Coordinate.PRECISION.S, Coordinate:new{latitude = 1 + 7 / 3600, longitude = 0}.precision)
	self:assertEquals(Coordinate.PRECISION.MS100, Coordinate:new{latitude = 1 + 7 / 3600 / 10, longitude = 0}.precision)
	self:assertEquals(Coordinate.PRECISION.MS10, Coordinate:new{latitude = 1 + 7 / 3600 / 100, longitude = 0}.precision)
	self:assertEquals(Coordinate.PRECISION.MS, Coordinate:new{latitude = 1 + 7 / 3600 / 1000, longitude = 0}.precision)
	self:assertEquals(Coordinate.PRECISION.D000001, Coordinate:new{latitude = 1 + 18 / 3600 / 1000, longitude = 0}.precision)
	self:assertEquals(Coordinate.PRECISION.D1, Coordinate:new{latitude = 1.7, longitude = 0}.precision)
	self:assertEquals(Coordinate.PRECISION.D01, Coordinate:new{latitude = 1.07, longitude = 0}.precision)
	self:assertEquals(Coordinate.PRECISION.M, Coordinate:new{latitude = 1.25, longitude = 0}.precision)
	self:assertEquals(Coordinate.PRECISION.D001, Coordinate:new{latitude = 1.007, longitude = 0}.precision)
	self:assertEquals(Coordinate.PRECISION.D0001, Coordinate:new{latitude = 1.0007, longitude = 0}.precision)
	self:assertEquals(Coordinate.PRECISION.D00001, Coordinate:new{latitude = 1.00007, longitude = 0}.precision)
	self:assertEquals(Coordinate.PRECISION.D000001, Coordinate:new{latitude = 1.000007, longitude = 0}.precision)
	self:assertEquals(Coordinate.PRECISION.D10, Coordinate:new{latitude = 10, longitude = 0}.precision)
	self:assertEquals(Coordinate.PRECISION.D000001, Coordinate:new{latitude = 3.14159265358, longitude = 0}.precision)
end

function suite:testDms()
	local coord = Coordinate:new { latitude=46.452739, longitude=24.61717, precision=1.0e-6 }
	local params, text = coord:toGeoHack('dms')
	self:assertEquals('<span class="latitude">é. sz. 46° 27′ 10″</span>, ' ..
		'<span class="longitude">k. h. 24° 37′ 02″</span>', text)
end

function suite:testValidateDms()
	self:assertFalse(Coordinate.validateDms('46', '27', '10', 'N', 'latitude'))
	self:assertFalse(Coordinate.validateDms('46.452739', nil, nil, nil, 'latitude'))
	self:assertFalse(Coordinate.validateDms('46', '27.166667', nil, 'N', 'latitude'))
	self:assertFalse(Coordinate.validateDms('46', '27', '9.983333', 'N', 'latitude'))
	self:assertFalse(Coordinate.validateDms('354.72', nil, nil, nil, 'longitude'))
	self:assertEquals('Missing degrees', Coordinate.validateDms(nil, '27', '10', 'N', 'latitude'))
	self:assertEquals('Invalid degrees', Coordinate.validateDms('X', '27', '10', 'N', 'latitude'))
	self:assertEquals('Invalid degrees', Coordinate.validateDms('146', '27', '10', 'N', 'latitude'))
	self:assertEquals('Invalid degrees', Coordinate.validateDms('454', '27', '10', 'N', 'longitude'))
	self:assertEquals('Invalid degrees', Coordinate.validateDms('-146.452739', nil, nil, nil, 'latitude'))
	self:assertEquals('Missing minutes', Coordinate.validateDms('46', nil, '10', 'N', 'latitude'))
	self:assertEquals('Invalid degrees', Coordinate.validateDms('46.452739', '27', '10', 'N', 'latitude'))
	self:assertEquals('Invalid degrees', Coordinate.validateDms('-46', '27', '10', 'N', 'latitude'))
	self:assertEquals('Invalid minutes', Coordinate.validateDms('46', 'X', '10', 'N', 'latitude'))
	self:assertEquals('Invalid minutes', Coordinate.validateDms('46', '-27', '10', 'N', 'latitude'))
	self:assertEquals('Invalid minutes', Coordinate.validateDms('46', '87', '10', 'N', 'latitude'))
	self:assertEquals('Invalid minutes', Coordinate.validateDms('46', '27.166667', '10', 'N', 'latitude'))
	self:assertEquals('Invalid seconds', Coordinate.validateDms('46', '27', 'X', 'N', 'latitude'))
	self:assertEquals('Invalid seconds', Coordinate.validateDms('46', '27', '-10', 'N', 'latitude'))
	self:assertEquals('Invalid seconds', Coordinate.validateDms('46', '27', '70', 'N', 'latitude'))
end

function suite:testCoord()
	self:markTestSkipped()
    local pageName = mw.uri.encode(mw.title.getCurrentTitle().prefixedText, 'WIKI')
    
    local text = '<span class="plainlinks nourlexpansion">[https://geohack.toolforge.org/geohack.php?language=hu' .. 
        '&pagename=' .. pageName .. '&params=47.05;-16.5_type:waterbody <span style="white-space:nowrap;">é. sz. 47,05°</span>, ' .. 
        '<span style="white-space:nowrap;">ny. h. 16,50°</span>]' .. 
        '<span style="display:none;" class="h-geo geo"><span class="p-latitude latitude">47.05</span>, ' .. 
        '<span class="p-longitude longitude">-16.5</span></span></span>'
    self:assertEquals(text, Coordinate.coord{'47.05', '-16.5', 'type:waterbody'})
    
    local text = '<span class="plainlinks nourlexpansion">[https://geohack.toolforge.org/geohack.php?language=hu' .. 
        '&pagename=' .. pageName .. '&params=47.05;-16.5 <span style="white-space:nowrap;">é. sz. 47° 03′ 00″</span>, ' .. 
        '<span style="white-space:nowrap;">ny. h. 16° 30′ 00″</span>]' .. 
        '<span style="display:none;" class="h-geo geo"><span class="p-latitude latitude">47.05</span>, ' .. 
        '<span class="p-longitude longitude">-16.5</span></span></span>'
    self:assertEquals(text, Coordinate.coord{'47.05', '-16.5', format = 'dms'})
    
    local text = '<span class="plainlinks nourlexpansion">[https://geohack.toolforge.org/geohack.php?language=hu' .. 
        '&pagename=' .. pageName .. '&params=43.651234;-79.383333 <span style="white-space:nowrap;">é. sz. 43,651234°</span>, ' .. 
        '<span style="white-space:nowrap;">ny. h. 79,383333°</span>]' .. 
        '<span style="display:none;" class="h-geo geo"><span class="p-latitude latitude">43.651234</span>, ' .. 
        '<span class="p-longitude longitude">-79.383333</span></span></span>'
    self:assertResultEquals(text, '{{Koord|43.651234|-79.383333}}')
    
    local text = '<span class="plainlinks nourlexpansion">[https://geohack.toolforge.org/geohack.php?language=hu' .. 
        '&pagename=' .. pageName .. '&params=43.65;-79.38 <span style="white-space:nowrap;">é. sz. 43,65°</span>, ' .. 
        '<span style="white-space:nowrap;">ny. h. 79,38°</span>]' .. 
        '<span style="display:none;" class="h-geo geo"><span class="p-latitude latitude">43.65</span>, ' .. 
        '<span class="p-longitude longitude">-79.38</span></span></span>'
    self:assertResultEquals(text, '{{Koord|43.65|-79.38}}')
    
    local text = '<span class="plainlinks nourlexpansion">[https://geohack.toolforge.org/geohack.php?language=hu' .. 
        '&pagename=' .. pageName .. '&params=43.65;-79.38 <span style="white-space:nowrap;">é. sz. 43,6500°</span>, ' .. 
        '<span style="white-space:nowrap;">ny. h. 79,3800°</span>]' .. 
        '<span style="display:none;" class="h-geo geo"><span class="p-latitude latitude">43.65</span>, ' .. 
        '<span class="p-longitude longitude">-79.38</span></span></span>'
    self:assertResultEquals(text, '{{Koord|43.6500|-79.3800}}')
    
    local text = '<span class="plainlinks nourlexpansion">[https://geohack.toolforge.org/geohack.php?language=hu' .. 
        '&pagename=' .. pageName .. '&params=43.651234;-79.383333 <span style="white-space:nowrap;">é. sz. 43,651234°</span>, ' .. 
        '<span style="white-space:nowrap;">ny. h. 79,383333°</span>]' .. 
        '<span style="display:none;" class="h-geo geo"><span class="p-latitude latitude">43.651234</span>, ' .. 
        '<span class="p-longitude longitude">-79.383333</span></span></span>'
    self:assertResultEquals(text, '{{Koord|43.651234|N|79.383333|W}}')
    
    local text = '<span class="plainlinks nourlexpansion">[https://geohack.toolforge.org/geohack.php?language=hu' .. 
        '&pagename=' .. pageName .. '&params=43_29_N_79_23_W <span style="white-space:nowrap;">é. sz. 43° 29′</span>, ' .. 
        '<span style="white-space:nowrap;">ny. h. 79° 23′</span>]' .. 
        '<span style="display:none;" class="h-geo geo"><span class="p-latitude latitude">43.483333333333</span>, ' .. 
        '<span class="p-longitude longitude">-79.383333333333</span></span></span>'
    self:assertResultEquals(text, '{{Koord|43|29|N|79|23|W}}')
    
    local text = '<span class="plainlinks nourlexpansion">[https://geohack.toolforge.org/geohack.php?language=hu' .. 
        '&pagename=' .. pageName .. '&params=43_29_4_N_79_23_0_W <span style="white-space:nowrap;">é. sz. 43° 29′ 04″</span>, ' .. 
        '<span style="white-space:nowrap;">ny. h. 79° 23′ 00″</span>]' .. 
        '<span style="display:none;" class="h-geo geo"><span class="p-latitude latitude">43.484444444444</span>, ' .. 
        '<span class="p-longitude longitude">-79.383333333333</span></span></span>'
    self:assertResultEquals(text, '{{Koord|43|29|4|N|79|23|0|W}}')
    
    local text = '<span class="plainlinks nourlexpansion">[https://geohack.toolforge.org/geohack.php?language=hu' .. 
        '&pagename=' .. pageName .. '&params=43_29_4.5_N_79_23_0.5_W <span style="white-space:nowrap;">é. sz. 43° 29′ 04″</span>, ' .. 
        '<span style="white-space:nowrap;">ny. h. 79° 23′ 00″</span>]' .. 
        '<span style="display:none;" class="h-geo geo"><span class="p-latitude latitude">43.484583333333</span>, ' .. 
        '<span class="p-longitude longitude">-79.383472222222</span></span></span>'
    self:assertResultEquals(text, '{{Koord|43|29|4.5|N|79|23|0.5|W}}')
    
    local text = '<span class="plainlinks nourlexpansion">[https://geohack.toolforge.org/geohack.php?language=hu' .. 
        '&pagename=' .. pageName .. '&params=55.752222;37.615556 <span style="white-space:nowrap;">é. sz. 55,752222°</span>, ' .. 
        '<span style="white-space:nowrap;">k. h. 37,615556°</span>]' .. 
        '<span style="display:none;" class="h-geo geo"><span class="p-latitude latitude">55.752222</span>, ' .. 
        '<span class="p-longitude longitude">37.615556</span></span></span>'
    self:assertResultEquals(text, '{{Koord|55.752222|N|37.615556|E}}')
    
    local text = '<span class="plainlinks nourlexpansion">[https://geohack.toolforge.org/geohack.php?language=hu' .. 
        '&pagename=' .. pageName .. '&params=55.752222;37.615556 <span style="white-space:nowrap;">é. sz. 55° 45′ 08″</span>, ' .. 
        '<span style="white-space:nowrap;">k. h. 37° 36′ 56″</span>]' .. 
        '<span style="display:none;" class="h-geo geo"><span class="p-latitude latitude">55.752222</span>, ' .. 
        '<span class="p-longitude longitude">37.615556</span></span></span>'
    self:assertResultEquals(text, '{{Koord|55.752222|N|37.615556|E|format=dms}}')
    
    local text = '<span class="plainlinks nourlexpansion">[https://geohack.toolforge.org/geohack.php?language=hu' .. 
        '&pagename=' .. pageName .. '&params=39.098095;-94.587307 <span style="white-space:nowrap;">é. sz. 39° 05′ 53″</span>, ' .. 
        '<span style="white-space:nowrap;">ny. h. 94° 35′ 14″</span>]' .. 
        '<span style="display:none;" class="h-geo geo"><span class="p-latitude latitude">39.098095</span>, ' .. 
        '<span class="p-longitude longitude">-94.587307</span></span></span>'
    self:assertResultEquals(text, '{{Koord|39.098095|-94.587307|format=dms}}')
    
    local text = '<span class="plainlinks nourlexpansion">[https://geohack.toolforge.org/geohack.php?language=hu' .. 
        '&pagename=' .. pageName .. '&params=55.752222;37.615556&title=Moscow ' .. 
        '<span style="white-space:nowrap;">é. sz. 55,752222°</span>, ' .. 
        '<span style="white-space:nowrap;">k. h. 37,615556°</span>]' .. 
        '<span style="display:none;" class="h-geo geo"><span class="p-latitude latitude">55.752222</span>, ' .. 
        '<span class="p-longitude longitude">37.615556</span></span></span>'
    self:assertResultEquals(text, '{{Koord|55.752222|N|37.615556|E|format=dec|name=Moscow}}')
    
    local text = '<span class="plainlinks nourlexpansion">[https://geohack.toolforge.org/geohack.php?language=hu' .. 
        '&pagename=' .. pageName .. '&params=33_55_S_18_25_E <span style="white-space:nowrap;">d. sz. 33° 55′</span>, ' .. 
        '<span style="white-space:nowrap;">k. h. 18° 25′</span>]' .. 
        '<span style="display:none;" class="h-geo geo"><span class="p-latitude latitude">-33.916666666667</span>, ' .. 
        '<span class="p-longitude longitude">18.416666666667</span></span></span>'
    self:assertResultEquals(text, '{{Koord|33|55|S|18|25|E}}')
    
    local text = '<span class="plainlinks nourlexpansion">[https://geohack.toolforge.org/geohack.php?language=hu' .. 
        '&pagename=' .. pageName .. '&params=35_0_N_105_0_E <span style="white-space:nowrap;">é. sz. 35° 00′</span>, ' .. 
        '<span style="white-space:nowrap;">k. h. 105° 00′</span>]' .. 
        '<span style="display:none;" class="h-geo geo"><span class="p-latitude latitude">35</span>, ' .. 
        '<span class="p-longitude longitude">105</span></span></span>'
    self:assertResultEquals(text, '{{Koord|35|00|N|105|00|E}}')
    
    local text = '<span class="plainlinks nourlexpansion">[https://geohack.toolforge.org/geohack.php?language=hu' .. 
        '&pagename=' .. pageName .. '&params=22_54_30_S_43_14_37_W <span style="white-space:nowrap;">d. sz. 22° 54′ 30″</span>, ' .. 
        '<span style="white-space:nowrap;">ny. h. 43° 14′ 37″</span>]' .. 
        '<span style="display:none;" class="h-geo geo"><span class="p-latitude latitude">-22.908333333333</span>, ' .. 
        '<span class="p-longitude longitude">-43.243611111111</span></span></span>'
    self:assertResultEquals(text, '{{Koord|22|54|30|S|43|14|37|W}}')
    
    local text = '<span class="plainlinks nourlexpansion">[https://geohack.toolforge.org/geohack.php?language=hu' .. 
        '&pagename=' .. pageName .. '&params=-22;-43 <span style="white-space:nowrap;">d. sz. 22°</span>, ' .. 
        '<span style="white-space:nowrap;">ny. h. 43°</span>]' .. 
        '<span style="display:none;" class="h-geo geo"><span class="p-latitude latitude">-22</span>, ' .. 
        '<span class="p-longitude longitude">-43</span></span></span>'
    self:assertResultEquals(text, '{{Koord|22|S|43|W}}')
    
    local text = '<span class="plainlinks nourlexpansion">[https://geohack.toolforge.org/geohack.php?language=hu' .. 
        '&pagename=' .. pageName .. '&params=52_28_N_1_55_W_region:GB_type:city <span style="white-space:nowrap;">é. sz. 52° 28′</span>, ' .. 
        '<span style="white-space:nowrap;">ny. h. 1° 55′</span>]' .. 
        '<span style="display:none;" class="h-geo geo"><span class="p-latitude latitude">52.466666666667</span>, ' .. 
        '<span class="p-longitude longitude">-1.9166666666667</span></span></span>Notes' .. 
        '<span style="font-size:small;"><span id="coordinates">[[Földrajzi koordináta-rendszer|Koordináták]]: ' .. 
        '<span class="plainlinks nourlexpansion">[https://geohack.toolforge.org/geohack.php?language=hu' .. 
        '&pagename=' .. pageName .. '&params=52_28_N_1_55_W_region:GB_type:city <span style="white-space:nowrap;">é. sz. 52° 28′</span>, ' .. 
        '<span style="white-space:nowrap;">ny. h. 1° 55′</span>]' .. 
        '<span style="display:none;" class="h-geo geo"><span class="p-latitude latitude">52.466666666667</span>, ' .. 
        '<span class="p-longitude longitude">-1.9166666666667</span></span></span>Notes</span></span>'
    self:assertResultEquals(text, '{{Koord|52|28|N|1|55|W|region:GB_type:city|notes=Notes|display=inline,title}}')

	local text = '<span class="plainlinks nourlexpansion">[https://geohack.toolforge.org/geohack.php?language=hu' .. 
		'&pagename=' .. pageName .. '&params=1;0 <span style="white-space:nowrap;">é. sz. 1°</span>, ' .. 
		'<span style="white-space:nowrap;">k. h. 0°</span>]' .. 
		'<span style="display:none;" class="h-geo geo"><span class="p-latitude latitude">1</span>, ' .. 
		'<span class="p-longitude longitude">0</span></span></span>'
	self:assertResultEquals(text, '{{Koord|1|0|precision=wikidata}}')

	local text = '<span class="plainlinks nourlexpansion">[https://geohack.toolforge.org/geohack.php?language=hu' .. 
		'&pagename=' .. pageName .. '&params=1_7_N_0_0_E <span style="white-space:nowrap;">é. sz. 1° 07′</span>, ' .. 
		'<span style="white-space:nowrap;">k. h. 0° 00′</span>]' .. 
		'<span style="display:none;" class="h-geo geo"><span class="p-latitude latitude">1.1166666666667</span>, ' .. 
		'<span class="p-longitude longitude">0</span></span></span>'
	self:assertResultEquals(text, '{{Koord|1.1166666666667|0|precision=wikidata}}')
end

return suite