Code: Selecteer alles
// File: TestProgramma.cp
// Date: 17 December 2006.
// Version: 197 microseconds on PowerMac G3/233 MHz.
//
// Copyright (c) 2006 Cliff Huylebroeck. All Rights Reserved.
//
// Permission to use, copy, modify, and distribute this software
// and its documentation for NON-COMMERCIAL purposes and without
// fee is hereby granted provided that this copyright notice
// appears in all copies.
//
// Cliff Huylebroeck MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
// SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT
// NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
// a PARTICULAR PURPOSE, OR NON-INFRINGEMENT. Cliff Huylebroeck SHALL NOT
// BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
// MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
#include "TestProgramma.h"
#include "BlockMove.h"
#include "collect.h"
#include "Debug.h"
#include "noErr.h"
#include "ProfilerDump.h"
#include "ProfilerInit.h"
#include "ProfilerTerm.h"
#include "Progressie.h"
#include "RandomGenerator.h"
#include "TestSnelheid.h"
#include "timeBase.h"
#if PROFILE_ALLES
#pragma profile on
#endif
c_n1 volledigeCijfers[aVakken]=
{
8,3,5,9,6,7,2,4,1,
9,7,4,3,1,2,8,6,5,
2,6,1,5,4,8,3,9,7,
3,9,8,2,7,5,6,1,4,
6,4,7,8,9,1,5,3,2,
5,1,2,6,3,4,9,7,8,
4,5,6,7,8,9,1,2,3,
7,8,9,1,2,3,4,5,6,
1,2,3,4,5,6,7,8,9
};
c_n1 streekkrantOpgaveCijfers[]=
{
7,0,0,0,0,4,0,0,3,
2,0,0,0,0,3,4,7,8,
0,4,3,0,7,1,0,0,0,
3,2,0,0,0,0,5,4,0,
0,0,0,0,0,0,0,0,0,
0,7,6,0,0,0,0,3,1,
0,0,0,4,8,0,7,1,0,
6,5,7,2,0,0,0,0,4,
4,0,0,3,0,0,0,0,2
};
c_n1 streekkrantOplossingCijfers[]=
{
7,9,5,8,2,4,1,6,3,
2,6,1,5,9,3,4,7,8,
8,4,3,6,7,1,2,5,9,
3,2,9,1,6,8,5,4,7,
1,8,4,7,3,5,9,2,6,
5,7,6,9,4,2,8,3,1,
9,3,2,4,8,6,7,1,5,
6,5,7,2,1,9,3,8,4,
4,1,8,3,5,7,6,9,2
};
#if not PROFILE_ALLES
#pragma profile on
#endif
void VergelijkendeTests()
{
if (true)
{
Kopieer();
}
if (true)
{
Tel();
}
if (true)
{
Snelheidstest();
}
}
#if not PROFILE_ALLES
#pragma profile off
#endif
void Kopieer()
{
Puzzel bron;
Puzzel doel;
Kopieer_MEET(bron,
doel);
}
#if not PROFILE_ALLES
#pragma profile on
#endif
void Kopieer_MEET(rc_Puzzel bron,
r_Puzzel doel)
{
::BlockMove(&bron,
&doel,
sizeof(Puzzel));
}
#if not PROFILE_ALLES
#pragma profile off
#endif
void Tel()
{
Buffer volledig(volledigeCijfers);
Tel_MEET(volledig);
}
#if not PROFILE_ALLES
#pragma profile on
#endif
void Tel_MEET(rc_Buffer volledig)
{
c_bool isOplossing=volledig.IsOplossing();
}
#if not PROFILE_ALLES
#pragma profile off
#endif
void Snelheidstest()
{
InitSnelheidstest();
Snelheidstest_MEET();
}
#if not PROFILE_ALLES
#pragma profile on
#endif
void Snelheidstest_MEET()
{
DoeSnelheidstest();
}
#if not PROFILE_ALLES
#pragma profile off
#endif
bool IsJuistNageteld(rc_Puzzel puzzel)
{
Buffer uitvoer;
puzzel.Schrijf(uitvoer);
c_bool isOpgelost=uitvoer.IsOplossing();
if (debug)
{
window.Schrijf("\pHet is ");
if (isOpgelost)
{
window.Schrijf("\pjuist");
}
else
{
window.Schrijf("\pverkeerd");
}
window.Schrijf("\p opgelost.");
window.SchrijfLn();
}
return isOpgelost;
}
void HerbeginEnDump(rc_Buffer opgave,
rc_Buffer mogelijkeOplossing)
{
if (debug)
{
Debug::StartUitvoer();
window.Schrijf("\pDe opgave is:");
window.SchrijfLn();
opgave.Debug_Dump();
Puzzel dubbel;
dubbel.LosOp(opgave);
window.Schrijf("\pEen mogelijke oplossing is:");
window.SchrijfLn();
mogelijkeOplossing.Debug_Dump();
Debug::StopUitvoer();
}
}
bool LosLegePuzzelOp()
{
Buffer oplossing(volledigeCijfers);
Buffer opgave;
oplossing.Schrap(aVakken,
opgave);
Puzzel puzzel;
if (!LosLegePuzzelOp_MEET(puzzel,
opgave))
{
HerbeginEnDump(opgave,
oplossing);
return false;
}
if (!IsJuistNageteld(puzzel))
{
HerbeginEnDump(opgave,
oplossing);
return false;
}
return true;
}
#if not PROFILE_ALLES
#pragma profile on
#endif
bool LosLegePuzzelOp_MEET(r_Puzzel puzzel,
rc_Buffer opgave)
{
c_bool isOpgelost=puzzel.LosOp(opgave);
return isOpgelost;
}
#if not PROFILE_ALLES
#pragma profile off
#endif
bool LosVolledigePuzzelOp()
{
Buffer oplossing(volledigeCijfers);
Buffer opgave(volledigeCijfers);
Puzzel puzzel;
if (!LosVolledigePuzzelOp_MEET(puzzel,
opgave))
{
HerbeginEnDump(opgave,
oplossing);
return false;
}
if (!IsJuistNageteld(puzzel))
{
HerbeginEnDump(opgave,
oplossing);
return false;
}
return true;
}
#if not PROFILE_ALLES
#pragma profile on
#endif
bool LosVolledigePuzzelOp_MEET(r_Puzzel puzzel,
rc_Buffer opgave)
{
c_bool isOpgelost=puzzel.LosOp(opgave);
return isOpgelost;
}
#if not PROFILE_ALLES
#pragma profile off
#endif
bool LosStreekkrantPuzzelOp()
{
Buffer opgave(streekkrantOpgaveCijfers);
Buffer oplossing(streekkrantOplossingCijfers);
Puzzel puzzel;
if (!LosStreekkrantPuzzelOp_MEET(puzzel,
opgave))
{
HerbeginEnDump(opgave,
oplossing);
return false;
}
if (!IsJuistNageteld(puzzel))
{
HerbeginEnDump(opgave,
oplossing);
return false;
}
return true;
}
#if not PROFILE_ALLES
#pragma profile on
#endif
bool LosStreekkrantPuzzelOp_MEET(r_Puzzel puzzel,
rc_Buffer opgave)
{
c_bool isOpgelost=puzzel.LosOp(opgave);
return isOpgelost;
}
#if not PROFILE_ALLES
#pragma profile off
#endif
bool LosPuzzelsMet32CijfersOp(c_n4 aPuzzels)
{
if (progressie)
{
Progressie::Herbegin();
}
c_n1 aIngevuldeVakken=32;
c_n1 aLegeVakken=aVakken-aIngevuldeVakken;
for (n4 i=0;i<aPuzzels;i++)
{
if (progressie)
{
if (Progressie::ErIsEenSecondeVoorbij())
{
Progressie::Schrijf(i);
}
}
Buffer oplossing;
oplossing.MaakRandom();
Buffer opgave;
oplossing.Schrap(aLegeVakken,
opgave);
Puzzel puzzel;
if (!LosPuzzelMet32CijfersOp_MEET(puzzel,
opgave))
{
HerbeginEnDump(opgave,
oplossing);
return false;
}
if (!IsJuistNageteld(puzzel))
{
HerbeginEnDump(opgave,
oplossing);
return false;
}
}
return true;
}
#if not PROFILE_ALLES
#pragma profile on
#endif
bool LosPuzzelMet32CijfersOp_MEET(r_Puzzel puzzel,
rc_Buffer opgave)
{
c_bool isOpgelost=puzzel.LosOp(opgave);
return isOpgelost;
}
bool Puzzeltest()
{
if (debug)
{
Debug::Init();
}
Puzzel::Init();
if (true)
{
if (!LosLegePuzzelOp())
{
return false;
}
}
if (true)
{
if (!LosVolledigePuzzelOp())
{
return false;
}
}
if (true)
{
if (!LosStreekkrantPuzzelOp())
{
return false;
}
}
if (true)
{
if (!LosPuzzelsMet32CijfersOp(1000000))
{
return false;
}
}
return true;
}
#if not PROFILE_ALLES
#pragma profile off
#endif
int main()
{
z2 err=::ProfilerInit(collectDetailed,
bestTimeBase,
static_cast<z2>(1000),
static_cast<z2>(100));
if (err!=noErr)
{
return 0;
}
if (progressie)
{
Progressie::Init();
}
Init_Coordinaten();
if (true)
{
VergelijkendeTests();
}
if (true)
{
if (!Puzzeltest())
{
if (debug)
{
window.Schrijf("\pTest is mislukt.");
window.SchrijfLn();
}
}
}
err=::ProfilerDump("\p:Profiel:Sudoku profiel");
if (err!=noErr)
{
return 0;
}
::ProfilerTerm();
return 0;
}