Module:Pgn/testcases

-- Unit tests for [[Module:Pgn]]. Click talk page to run tests.
local p = require('Module:UnitTests')
local pgnModule = require('Module:Pgn')
 
-- test extraction of moves to FEN notation - main functionality of the module
function p:testFullPgnMoves()
	local pgn=[[[Event "World Cup"]
[Site "Khanty-Mansiysk"]
[Date "2007.11.25"]
[Round "1.2"]
[White "Mamedyarov, Shakhriyar"]
[Black "Abdel Razik, Khaled"]
[Result "1-0"]
[ECO "D43"]
[WhiteElo "2752"]
[BlackElo "2389"]
[PlyCount "65"]
[EventDate "2007.11.24"]
[EventType "k.o."]
[EventRounds "7"]
[EventCountry "RUS"]
[Source "ChessBase"]
[SourceDate "2008.01.30"]

1. d4 e6 2. c4 Nf6 3. Nf3 d5 4. Nc3 c6 5. Bg5 h6 6. Bxf6 Qxf6 7. Qc2 Nd7 8. e4
dxe4 9. Qxe4 Bb4 10. Bd3 g6 11. O-O O-O 12. Qe3 Bxc3 13. bxc3 Kg7 14. a4 b6 15.
a5 Ba6 16. Rfb1 Rfc8 17. h4 b5 18. cxb5 Bxb5 19. Bxb5 cxb5 20. Rxb5 Rab8 21.
Rab1 Qf5 22. Rxb8 Rxb8 23. Rxb8 Nxb8 24. Ne5 h5 25. c4 f6 26. Qb3 fxe5 27. Qxb8
exd4 28. Qxa7+ Kg8 29. Qb8+ Kh7 30. a6 d3 31. a7 d2 32. a8=Q d1=Q+ 33. Kh2 1-0
]]

	metadata, moves = pgnModule.main(pgn)
	
    self:preprocess_equals(
    	moves[1],
    	'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR'
    )
    
    self:preprocess_equals(
    	moves[#moves],
    	'QQ6/7k/4p1p1/5q1p/2P4P/8/5PPK/3q4'
    )
end

--tests metadata extraction
function p:testFullPgnMetadata()
	local pgn=[[[Event "World Cup"]
[Site "Khanty-Mansiysk"]
[Date "2007.11.25"]
[Round "1.2"]
[White "Mamedyarov, Shakhriyar"]
[Black "Abdel Razik, Khaled"]
[Result "1-0"]
[ECO "D43"]
[WhiteElo "2752"]
[BlackElo "2389"]
[PlyCount "65"]
[EventDate "2007.11.24"]
[EventType "k.o."]
[EventRounds "7"]
[EventCountry "RUS"]
[Source "ChessBase"]
[SourceDate "2008.01.30"]

1. d4 e6 2. c4 Nf6 3. Nf3 d5 4. Nc3 c6 5. Bg5 h6 6. Bxf6 Qxf6 7. Qc2 Nd7 8. e4
dxe4 9. Qxe4 Bb4 10. Bd3 g6 11. O-O O-O 12. Qe3 Bxc3 13. bxc3 Kg7 14. a4 b6 15.
a5 Ba6 16. Rfb1 Rfc8 17. h4 b5 18. cxb5 Bxb5 19. Bxb5 cxb5 20. Rxb5 Rab8 21.
Rab1 Qf5 22. Rxb8 Rxb8 23. Rxb8 Nxb8 24. Ne5 h5 25. c4 f6 26. Qb3 fxe5 27. Qxb8
exd4 28. Qxa7+ Kg8 29. Qb8+ Kh7 30. a6 d3 31. a7 d2 32. a8=Q d1=Q+ 33. Kh2 1-0


]]
	metadata, moves = pgnModule.main(pgn)
    self:preprocess_equals( metadata['Black'] or '', 'Abdel Razik, Khaled' )
    self:preprocess_equals( metadata['White'] or '', 'Mamedyarov, Shakhriyar' )
end

-- tests algebric notation PGN with no metadata
function p:testAlgebricNotation()
	local pgn=[[1. d4 e6 2. c4 Nf6 3. Nf3 d5 4. Nc3 c6 5. Bg5 h6 6. Bxf6 Qxf6 7. Qc2 Nd7 8. e4
dxe4 9. Qxe4 Bb4 10. Bd3 g6 11. O-O O-O 12. Qe3 Bxc3 13. bxc3 Kg7 14. a4 b6 15.
a5 Ba6 16. Rfb1 Rfc8 17. h4 b5 18. cxb5 Bxb5 19. Bxb5 cxb5 20. Rxb5 Rab8 21.
Rab1 Qf5 22. Rxb8 Rxb8 23. Rxb8 Nxb8 24. Ne5 h5 25. c4 f6 26. Qb3 fxe5 27. Qxb8
exd4 28. Qxa7+ Kg8 29. Qb8+ Kh7 30. a6 d3 31. a7 d2 32. a8=Q d1=Q+ 33. Kh2 1-0
]]
	local metadata, moves
	success, metadata, moves = pcall(pgnModule.main,pgn)
	if not success then
		moves  = {'fail'}
	end
	
    self:preprocess_equals(
    	moves[1],
    	'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR'
    )
    
    self:preprocess_equals(
    	moves[#moves],
    	'QQ6/7k/4p1p1/5q1p/2P4P/8/5PPK/3q4'
    )
end

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.