//////////////////////////////////////////////////
// TimeUtil

QUnit.test( "TimeUtil", function( assert ) {
	var SEC_MS = 1000;
	var MIN_MS = 60 * SEC_MS;
	var HR_MS = 60 * MIN_MS;
	var DAY_MS = 24 * HR_MS;

	var testDay = 1 * DAY_MS;
	var testHour = 23 * HR_MS;
	var testMinute = 11 * MIN_MS;
	var testSecond = 56 * SEC_MS;
	var testMilliSecond = 123;
	var testTimeMS = testDay + testHour + testMinute + testSecond + testMilliSecond;

	assert.equal(TimeUtil.getFullSecondFromMS(testTimeMS), 169916, "getFullSecondFromMS");
	assert.equal(TimeUtil.getSecondFromMS(testTimeMS), 56, "getSecondFromMS");
	assert.equal(TimeUtil.getTwoDigitSecondFromMS(testTimeMS), "56", "getTwoDigitSecondFromMS");

	assert.equal(TimeUtil.getFullMinuteFromMS(testTimeMS), 2831, "getFullMinuteFromMS");
	assert.equal(TimeUtil.getMinuteFromMS(testTimeMS), 11, "getMinuteFromMS");
	assert.equal(TimeUtil.getTwoDigitMinuteFromMS(testTimeMS), "11", "getTwoDigitMinuteFromMS");

	assert.equal(TimeUtil.getFullHourFromMS(testTimeMS), 47, "getFullHourFromMS");
	assert.equal(TimeUtil.getHourFromMS(testTimeMS), 23, "getHourFromMS");
	assert.equal(TimeUtil.getTwoDigitHourFromMS(testTimeMS), "23", "getTwoDigitHourFromMS");


	testDay = 0 * DAY_MS;
	testHour = 9 * HR_MS;
	testMinute = 5 * MIN_MS;
	testSecond = 4 * SEC_MS;
	testMilliSecond = 1;
	testTimeMS = testDay + testHour + testMinute + testSecond + testMilliSecond;

	assert.equal(TimeUtil.getFullSecondFromMS(testTimeMS), 32704, "getFullSecondFromMS");
	assert.equal(TimeUtil.getSecondFromMS(testTimeMS), 4, "getSecondFromMS");
	assert.equal(TimeUtil.getTwoDigitSecondFromMS(testTimeMS), "04", "getTwoDigitSecondFromMS");

	assert.equal(TimeUtil.getFullMinuteFromMS(testTimeMS), 545, "getFullMinuteFromMS");
	assert.equal(TimeUtil.getMinuteFromMS(testTimeMS), 5, "getMinuteFromMS");
	assert.equal(TimeUtil.getTwoDigitMinuteFromMS(testTimeMS), "05", "getTwoDigitMinuteFromMS");

	assert.equal(TimeUtil.getFullHourFromMS(testTimeMS), 9, "getFullHourFromMS");
	assert.equal(TimeUtil.getHourFromMS(testTimeMS), 9, "getHourFromMS");
	assert.equal(TimeUtil.getTwoDigitHourFromMS(testTimeMS), "09", "getTwoDigitHourFromMS");

	testTimeMS = 3000;
	assert.equal(TimeUtil.getTwoDigitSecondFromMS(testTimeMS), "03", "getTwoDigitHourFromMS");
});


//////////////////////////////////////////////////
// app list DB

QUnit.test( "AppList", function( assert ) {
	var MAESTRO_ID		= 3;	// 삼화초
	var PLAYER_ID		= 35;	// 박지상

	var dbService = new DBService();
	dbService.setMaestroID(MAESTRO_ID);
	dbService.setPlayerID(PLAYER_ID);

	var asyncTypingPracticeKorean = assert.async();
	setTimeout(function() {
		var appGroup = 0;	// typing practice
		var language = 0;	// Korean
		dbService.requestMainMenuAppData(
			appGroup,
			language,
			(function(jsonData) {
				assert.equal(jsonData.appGroup, appGroup, "#0 appGroup : typing practice, Korean");
				assert.equal(jsonData.appData.appList.length, 8, "appList");
				assert.equal(jsonData.appData.activeAppList.length, 7, "activeAppList");
				assert.equal(jsonData.appData.highestRecordList.length, 8, "highestRecordList");
				asyncTypingPracticeKorean();
			}).bind(this),
			(function(jsonData) {
				console.log(replyJSON);
				asyncTypingPracticeKorean();
			}).bind(this)
		);
	});

	var asyncTypingPracticeEnglish = assert.async();
	setTimeout(function() {
		var appGroup = 0;	// typing practice
		var language = 1;	// English
		dbService.requestMainMenuAppData(
			appGroup,
			language,
			(function(jsonData) {
				assert.equal(jsonData.appGroup, appGroup, "#0 appGroup : typing practice, English");
				assert.equal(jsonData.appData.appList.length, 7, "appList");
				assert.equal(jsonData.appData.activeAppList.length, 6, "activeAppList");
				assert.equal(jsonData.appData.highestRecordList.length, 7, "highestRecordList");
				asyncTypingPracticeEnglish();
			}).bind(this),
			(function(jsonData) {
				console.log(replyJSON);
				asyncTypingPracticeEnglish();
			}).bind(this)
		);
	});

	var asyncTestKorean = assert.async();
	setTimeout(function() {
		var appGroup = 1;	// typing test
		var language = 0;	// Korean
		dbService.requestMainMenuAppData(
			appGroup,
			language,
			(function(jsonData) {
				assert.equal(jsonData.appGroup, appGroup, "#1 appGroup : typing test, Korean");
				assert.equal(jsonData.appData.appList.length, 10, "appList");
				assert.equal(jsonData.appData.activeAppList.length, 7, "activeAppList");
				assert.equal(jsonData.appData.highestRecordList.length, 10, "highestRecordList");
				asyncTestKorean();
			}).bind(this),
			(function(jsonData) {
				console.log(replyJSON);
				asyncTestKorean();
			}).bind(this)
		);
	});

	var asyncTestEnglish = assert.async();
	setTimeout(function() {
		var appGroup = 1;	// typing test
		var language = 1;	// English
		dbService.requestMainMenuAppData(
			appGroup,
			language,
			(function(jsonData) {
				assert.equal(jsonData.appGroup, appGroup, "#1 appGroup : typing test, English");
				assert.equal(jsonData.appData.appList.length, 8, "appList");
				assert.equal(jsonData.appData.activeAppList.length, 3, "activeAppList");
				assert.equal(jsonData.appData.highestRecordList.length, 8, "highestRecordList");
				asyncTestEnglish();
			}).bind(this),
			(function(jsonData) {
				console.log(replyJSON);
				asyncTestEnglish();
			}).bind(this)
		);
	});

	var asyncExamKorean = assert.async();
	setTimeout(function() {
		var appGroup = 2;	// typing exam
		var language = 0;	// Korean
		dbService.requestMainMenuAppData(
			appGroup,
			language,
			(function(jsonData) {
				assert.equal(jsonData.appGroup, appGroup, "#2 appGroup : typing exam, Korean");
				assert.equal(jsonData.appData.appList.length, 5, "appList");
				assert.equal(jsonData.appData.activeAppList.length, 5, "activeAppList");
				assert.equal(jsonData.appData.highestRecordList.length, 5, "highestRecordList");
				asyncExamKorean();
			}).bind(this),
			(function(jsonData) {
				console.log(replyJSON);
				asyncExamKorean();
			}).bind(this)
		);
	});

	var asyncExamEnglish = assert.async();
	setTimeout(function() {
		var appGroup = 2;	// typing exam
		var language = 1;	// English
		dbService.requestMainMenuAppData(
			appGroup,
			language,
			(function(jsonData) {
				assert.equal(jsonData.appGroup, appGroup, "#2 appGroup : typing exam, English");
				// console.log(jsonData.appData);
				assert.equal(jsonData.appData.appList.length, 4, "appList");
				assert.equal(jsonData.appData.activeAppList.length, 4, "activeAppList");
				assert.equal(jsonData.appData.highestRecordList.length, 4, "highestRecordList");
				asyncExamEnglish();
			}).bind(this),
			(function(jsonData) {
				console.log(replyJSON);
				asyncExamEnglish();
			}).bind(this)
		);
	});

	var asyncTypingPlayKorean = assert.async();
	setTimeout(function() {
		var appGroup = 3;	// typing play
		var language = 0;	// Korean
		dbService.requestMainMenuAppData(
			appGroup,
			language,
			(function(jsonData) {
				assert.equal(jsonData.appGroup, appGroup, "#3 appGroup : typing play, Korean");
				assert.equal(jsonData.appData.appList.length, 2, "appList");
				assert.equal(jsonData.appData.activeAppList.length, 1, "activeAppList");
				assert.equal(jsonData.appData.highestRecordList.length, 2, "highestRecordList");
				asyncTypingPlayKorean();
			}).bind(this),
			(function(jsonData) {
				console.log(replyJSON);
				asyncTypingPlayKorean();
			}).bind(this)
		);
	});

	var asyncTypingPlayEnglish = assert.async();
	setTimeout(function() {
		var appGroup = 3;	// typing play
		var language = 1;	// English
		dbService.requestMainMenuAppData(
			appGroup,
			language,
			(function(jsonData) {
				assert.equal(jsonData.appGroup, appGroup, "#3 appGroup : typing play, English");
				assert.equal(jsonData.appData.appList.length, 2, "appList");
				assert.equal(jsonData.appData.activeAppList.length, 1, "activeAppList");
				assert.equal(jsonData.appData.highestRecordList.length, 2, "highestRecordList");
				asyncTypingPlayEnglish();
			}).bind(this),
			(function(jsonData) {
				console.log(replyJSON);
				asyncTypingPlayEnglish();
			}).bind(this)
		);
	});

	var asyncMousePlay = assert.async();
	setTimeout(function() {
		var appGroup = 4;	// mouse play
		var language = 0;	// Korean
		dbService.requestMainMenuAppData(
			appGroup,
			language,
			(function(jsonData) {
				assert.equal(jsonData.appGroup, appGroup, "#4 appGroup : mouse play");
				assert.equal(jsonData.appData.appList.length, 5, "appList");
				assert.equal(jsonData.appData.activeAppList.length, 4, "activeAppList");
				assert.equal(jsonData.appData.highestRecordList.length, 5, "highestRecordList");
				asyncMousePlay();
			}).bind(this),
			(function(jsonData) {
				console.log(replyJSON);
				asyncMousePlay();
			}).bind(this)
		);
	});

});

//////////////////////////////////////////////////
// typing exam highest record DB

QUnit.test( "TypingExamHighestRecord", function( assert ) {
	var MAESTRO_ID		= 3;	// 삼화초
	var PLAYER_ID		= 35;	// 박지상
	var WRITING_ID		= 1;
	var RECORD			= 123.456;

	var dbService = new DBService();
	dbService.setMaestroID(MAESTRO_ID);
	dbService.setPlayerID(PLAYER_ID);

	dbService.tddSetup(
		"deleteTypingExamHighestRecordAll",
		(function(jsonData) {		// onSucceeded
			// console.log(jsonData);
			addTypingExamHighestRecord();
		}).bind(this),
		(function(jsonData) {		// onFailed
			// console.log(jsonData);
		}).bind(this)
	);

	function addTypingExamHighestRecord()
	{
		dbService.tddRun(
			"addTypingExamHighestRecord",
			(function(jsonData) {		// onSucceeded
				// console.log(jsonData);
				updateTypingExamHighestRecord();
			}).bind(this),
			(function(jsonData) {		// onFailed
				// console.log(jsonData);
			}).bind(this)
		);
	}

	function updateTypingExamHighestRecord()
	{
		dbService.tddRun(
			"updateTypingExamHighestRecord",
			(function(jsonData) {		// onSucceeded
				// console.log(jsonData);
				getTypingExamHighestRecord();
			}).bind(this),
			(function(jsonData) {		// onFailed
				// console.log(jsonData);
			}).bind(this)
		);
	}

	var done = assert.async();
	function getTypingExamHighestRecord()
	{
		setTimeout(function() {
			var UPDATED_RECORD	= 133.456;

			dbService.tddRun(
				"getTypingExamHigestRecord",
				(function(jsonData) {		// onSucceeded
					// console.log(jsonData);

					var highestRecord = jsonData["typingExamHighestRecordData"];
					assert.equal(highestRecord["highestRecord"], UPDATED_RECORD, "highest record");
					done();
				}).bind(this),
				(function(jsonData) {		// onFailed
					// console.log(jsonData);
					done();
				}).bind(this)
			);
		});
	}

});


//////////////////////////////////////////////////
// typing exam DB

QUnit.test( "TypingExamDB", function( assert ) {
	var MAESTRO_ID		= 3;	// 삼화초
	var PLAYER_ID		= 35;	// 박지상
	var WRITING_ID		= 1;
	var RECORD			= 117.89;

	var dbService = new DBService();
	dbService.setMaestroID(MAESTRO_ID);
	dbService.setPlayerID(PLAYER_ID);

	dbService.tddSetup(
		"deleteWritingRecordAll",
		(function(jsonData) {		// onSucceeded
			// console.log(jsonData);
			addPrevHourTypingExamRecord();
		}).bind(this),
		(function(jsonData) {		// onFailed
			// console.log(jsonData);
		}).bind(this)
	);

	function addPrevHourTypingExamRecord()
	{
		dbService.addPrevHourTypingExamRecord(
			WRITING_ID,	//writingRecord
			RECORD + 10,	// record
			(function(jsonData) {		// onSucceeded
				// console.log(jsonData);
				updateTypingExamRecord();
			}).bind(this),
			(function(jsonData) {		// onFailed
				// console.log(jsonData);
			}).bind(this)
		);
	}

	// add this hour record - 10
	function updateTypingExamRecord()
	{
		dbService.updateTypingExamRecord(
			WRITING_ID,	//writingRecord
			RECORD - 10,	// record
			(function(jsonData) {		// onSucceeded
				// console.log(jsonData);
				updateTypingExamRecord2();
			}).bind(this),
			(function(jsonData) {		// onFailed
				// console.log(jsonData);
			}).bind(this)
		);
	}

	// update this hour record
	function updateTypingExamRecord2()
	{
		dbService.updateTypingExamRecord(
			WRITING_ID,	//writingRecord
			RECORD,	// record
			(function(jsonData) {		// onSucceeded
				// console.log(jsonData);
				getTypingExamHighestRecord();
			}).bind(this),
			(function(jsonData) {		// onFailed
				// console.log(jsonData);
			}).bind(this)
		);
	}

	var done = assert.async();
	function getTypingExamHighestRecord()
	{
		setTimeout(function() {
			dbService.getTypingExamHighestRecord(
				WRITING_ID,
				(function(jsonData) {		// onSucceeded
					// console.log(jsonData);

					var highestRecord = jsonData["highestRecordData"];
					assert.equal(highestRecord["highestRecord"], RECORD + 10, "highest record");
					updateTypingExamRecord3();
				}).bind(this),
				(function(jsonData) {		// onFailed
					// console.log(jsonData);
					done();
				}).bind(this)
			);
		});
	}

	// update this hour record
	function updateTypingExamRecord3()
	{
		dbService.updateTypingExamRecord(
			WRITING_ID,	//writingRecord
			RECORD + 20,	// record
			(function(jsonData) {		// onSucceeded
				// console.log(jsonData);
				getTypingExamHighestRecord2();
			}).bind(this),
			(function(jsonData) {		// onFailed
				// console.log(jsonData);
				done();
			}).bind(this)
		);
	}

	function getTypingExamHighestRecord2()
	{
		dbService.getTypingExamHighestRecord(
			WRITING_ID,
			(function(jsonData) {		// onSucceeded
				// console.log(jsonData);

				var highestRecord = jsonData["highestRecordData"];
				assert.equal(highestRecord["highestRecord"], RECORD + 20, "highest record");
				done();
			}).bind(this),
			(function(jsonData) {		// onFailed
				// console.log(jsonData);
				done();
			}).bind(this)
		);
	}

});


//////////////////////////////////////////////////
// typing exam DB - minus record

QUnit.test( "TypingExamDB - minus record", function( assert ) {
	var MAESTRO_ID		= 3;	// 삼화초
	var PLAYER_ID		= 35;	// 박지상
	var WRITING_ID		= 1;
	var RECORD			= -117.89;

	var dbService = new DBService();
	dbService.setMaestroID(MAESTRO_ID);
	dbService.setPlayerID(PLAYER_ID);

	dbService.tddSetup(
		"deleteWritingRecordAll",
		(function(jsonData) {		// onSucceeded
			// console.log(jsonData);
			addPrevHourTypingExamRecord();
		}).bind(this),
		(function(jsonData) {		// onFailed
			// console.log(jsonData);
		}).bind(this)
	);

	function addPrevHourTypingExamRecord()
	{
		console.log("record : " + RECORD);
		dbService.addPrevHourTypingExamRecord(
			WRITING_ID,	//writingRecord
			RECORD,	// record : -117.89
			(function(jsonData) {		// onSucceeded
				// console.log(jsonData);
				updateTypingExamRecord();
			}).bind(this),
			(function(jsonData) {		// onFailed
				// console.log(jsonData);
			}).bind(this)
		);
	}

	// add this hour record + 10
	function updateTypingExamRecord()
	{
		console.log("record : " + (RECORD + 20));
		dbService.updateTypingExamRecord(
			WRITING_ID,	//writingRecord
			RECORD + 20,	// record
			(function(jsonData) {		// onSucceeded
				// console.log(jsonData);
				updateTypingExamRecord2();

				// getTypingExamRecord();
			}).bind(this),
			(function(jsonData) {		// onFailed
				// console.log(jsonData);
			}).bind(this)
		);
	}

	// update this hour record
	function updateTypingExamRecord2()
	{
		dbService.updateTypingExamRecord(
			WRITING_ID,	//writingRecord
			RECORD,	// record
			(function(jsonData) {		// onSucceeded
				// console.log(jsonData);
				getTypingExamHighestRecord();
			}).bind(this),
			(function(jsonData) {		// onFailed
				// console.log(jsonData);
			}).bind(this)
		);
	}

	var done = assert.async();
	function getTypingExamRecord() {
		setTimeout(function() {
			dbService.getTypingExamHighestRecord(
				WRITING_ID,
				(function(jsonData) {		// onSucceeded
					// console.log(jsonData);

					var highestRecord = jsonData["highestRecordData"];
					assert.equal(highestRecord["highestRecord"], 0, "highest record");
					updateTypingExamRecord3();
				}).bind(this),
				(function(jsonData) {		// onFailed
					// console.log(jsonData);
					done();
				}).bind(this)
			);
		});
	}
	function getTypingExamHighestRecord()
	{
		setTimeout(function() {
			dbService.getTypingExamHighestRecord(
				WRITING_ID,
				(function(jsonData) {		// onSucceeded
					// console.log(jsonData);

					var highestRecord = jsonData["highestRecordData"];
					assert.equal(highestRecord["highestRecord"], null, "highest record");
					updateTypingExamRecord3();
				}).bind(this),
				(function(jsonData) {		// onFailed
					// console.log(jsonData);
					done();
				}).bind(this)
			);
		});
	}

	// update this hour record
	function updateTypingExamRecord3()
	{
		console.log("record : " + (RECORD - 10));
		dbService.updateTypingExamRecord(
			WRITING_ID,	//writingRecord
			RECORD - 10,	// record
			(function(jsonData) {		// onSucceeded
				// console.log(jsonData);
				getTypingExamHighestRecord2();
			}).bind(this),
			(function(jsonData) {		// onFailed
				// console.log(jsonData);
				done();
			}).bind(this)
		);
	}

	function getTypingExamHighestRecord2()
	{
		dbService.getTypingExamHighestRecord(
			WRITING_ID,
			(function(jsonData) {		// onSucceeded
				// console.log(jsonData);

				var highestRecord = jsonData["highestRecordData"];
				assert.equal(highestRecord["highestRecord"], null, "highest record");
				done();
			}).bind(this),
			(function(jsonData) {		// onFailed
				// console.log(jsonData);
				done();
			}).bind(this)
		);
	}

});


//////////////////////////////////////////////////
// DBConnector

QUnit.test( "DBConnector", function( assert ) {
	var dbService = new DBService();
	dbService.setMaestroID(3);	// 삼화초
	dbService.setPlayerID(35);	// 박지상

	var done = assert.async();
	setTimeout(function() {
		dbService.requestWritingPlayerList(
			(jsonData) => {		// onSucceeded
				// console.log(jsonData);

				var writingArray = jsonData["writingArray"];
				assert.equal(writingArray[0].name, "봄2", "name");
				assert.equal(writingArray[3].name, "허생전", "name");
				done();
			},
			(jsonData) => {		// onFailed
				// console.log(jsonData);
				done();
			}
		);
	});
});


//////////////////////////////////////////////////
// StringUtil

QUnit.test( "StringUtil", function( assert ) {
	var englishText = "Is hangle character?";
	var koreanText = "한글 단어 입니까?";
	var englishKoreanText = "Is 한글 character 입니까?";

	assert.equal(StringUtil.isKoreanAlphabet(englishText[0]), false, "StringUtil - isKoreanAlphabet");
	assert.equal(StringUtil.isKoreanAlphabet(koreanText[0]), true, "StringUtil - isKoreanAlphabet");

	assert.equal(StringUtil.getUnicodeAlphabetCount(englishText), 20, "StringUtil - getUnicodeAlphabetCount");
	assert.equal(StringUtil.getUnicodeAlphabetCount(koreanText), 17, "StringUtil - getUnicodeAlphabetCount");

	assert.equal(StringUtil.getMultibyteIndex(englishText, 0), 0, "StringUtil - getMultibyteIndex, eng");
	assert.equal(StringUtil.getMultibyteIndex(englishText, 1), 1, "StringUtil - getMultibyteIndex, eng");
	assert.equal(StringUtil.getMultibyteIndex(englishText, 3), 3, "StringUtil - getMultibyteIndex, eng");
	assert.equal(StringUtil.getMultibyteIndex(koreanText, 0), 0, "StringUtil - getMultibyteIndex, kor1");
	assert.equal(StringUtil.getMultibyteIndex(koreanText, 1), 0, "StringUtil - getMultibyteIndex, kor2");
	assert.equal(StringUtil.getMultibyteIndex(koreanText, 2), 1, "StringUtil - getMultibyteIndex, kor3");
	assert.equal(StringUtil.getMultibyteIndex(koreanText, 3), 1, "StringUtil - getMultibyteIndex, kor4");
	assert.equal(StringUtil.getMultibyteIndex(koreanText, 4), 2, "StringUtil - getMultibyteIndex, kor5");
	assert.equal(StringUtil.getMultibyteIndex(koreanText, 5), 3, "StringUtil - getMultibyteIndex, kor6");
	assert.equal(StringUtil.getMultibyteIndex(koreanText, 6), 3, "StringUtil - getMultibyteIndex, kor7");
	assert.equal(StringUtil.getMultibyteIndex(englishKoreanText, 0), 0, "StringUtil - getMultibyteIndex, engKor1");
	assert.equal(StringUtil.getMultibyteIndex(englishKoreanText, 1), 1, "StringUtil - getMultibyteIndex, engKor1");
	assert.equal(StringUtil.getMultibyteIndex(englishKoreanText, 2), 2, "StringUtil - getMultibyteIndex, engKor1");
	assert.equal(StringUtil.getMultibyteIndex(englishKoreanText, 3), 3, "StringUtil - getMultibyteIndex, engKor2");
	assert.equal(StringUtil.getMultibyteIndex(englishKoreanText, 4), 3, "StringUtil - getMultibyteIndex, engKor3");
	assert.equal(StringUtil.getMultibyteIndex(englishKoreanText, 5), 4, "StringUtil - getMultibyteIndex, engKor4");
});


//////////////////////////////////////////////////
// DateUtil

QUnit.test( "DateUtil", function( assert ) {
	var datetime = new Date("2019-06-04T16:15:03");

	var dateTimeText = "2019-06-04T16:00:00";
	var datetimeHour = new Date(dateTimeText);
	var roundedDateTimeText = DateUtil.getYYYYMMDD(datetime) + "T" + datetime.getHours() + ":00:00";
	var roundedDateTime = new Date(roundedDateTimeText);
	assert.equal(datetimeHour - roundedDateTime, 0, "DateUtil - roundedDateTime");


	var date = DateUtil.getFullYear(datetime) + "-"
		+ DateUtil.getFullMonth(datetime) + "-"
		+ DateUtil.getFullDate(datetime);
	var time = DateUtil.getFullHours(datetime) + ":"
		+ DateUtil.getFullMinutes(datetime) + ":"
		+ DateUtil.getFullSeconds(datetime);

	assert.equal(DateUtil.getFullYear(datetime), "2019", "DateUtil - getFullYear");
	assert.equal(DateUtil.getFullMonth(datetime), "06", "DateUtil - getFullMonth");
	assert.equal(DateUtil.getFullDate(datetime), "04", "DateUtil - getFullDate");

	assert.equal(DateUtil.getFullHours(datetime), "16", "DateUtil - getFullHours");
	assert.equal(DateUtil.getFullMinutes(datetime), "15", "DateUtil - getFullMinutes");
	assert.equal(DateUtil.getFullSeconds(datetime), "03", "DateUtil - getFullSeconds");

	assert.equal(DateUtil.getYYYYMMDD(datetime), date, "DateUtil - getYYYYMMDD");
	assert.equal(DateUtil.getHHMMSS(datetime), time, "DateUtil - getHHMMSS");
});


//////////////////////////////////////////////////
// App ranking

QUnit.test( "App ranking", function( assert ) {
	sessionStorageManager.setMaestroID(3);	// jisangs
	sessionStorageManager.setPlayingAppID(1);

	var dbConnectManager = new DBConnectManager();

	// #1 Hour 15:00
	let date = "2018-08-23";
	let time = "15:53:00";

	let done = assert.async();
	setTimeout(function() {
		dbConnectManager.requestRanking(
			DBConnectManager.TYPE_MY_RANKING_HOUR,
			sessionStorageManager.getMaestroID(),
			date,
			time,
			(type, rankingRecordManager) => {
				assert.equal(rankingRecordManager.getRankAt(0), 1, "hour - rank #1");
				assert.equal(rankingRecordManager.getBestRecordAt(0), 97.33, "hour - best record");
				assert.equal(rankingRecordManager.getPlayerIDAt(0), 49, "hour - player ID");
				assert.equal(rankingRecordManager.getPlayerNameAt(0), "마가연", "hour - player name");

				assert.equal(rankingRecordManager.getRankAt(5), 6, "hour - rank");
				assert.equal(rankingRecordManager.getBestRecordAt(5), 85.44, "hour - best record");
				assert.equal(rankingRecordManager.getPlayerIDAt(5), 79, "hour - player ID");
				assert.equal(rankingRecordManager.getPlayerNameAt(5), "박선수", "hour - player name");

				done();
			}
		);
	});

	// #2 Hour 16:00
	let date2 = "2018-08-23";
	let time2 = "16:53:00";

	let done2 = assert.async();
	setTimeout(function() {
		dbConnectManager.requestRanking(
			DBConnectManager.TYPE_MY_RANKING_HOUR,
			sessionStorageManager.getMaestroID(),
			date2,
			time2,
			(type, rankingRecordManager) => {
				assert.equal(rankingRecordManager.getRankAt(0), 1, "hour - rank #2");
				assert.equal(rankingRecordManager.getBestRecordAt(0), 97.87, "hour - best record");
				assert.equal(rankingRecordManager.getPlayerIDAt(0), 51, "hour - player ID");
				assert.equal(rankingRecordManager.getPlayerNameAt(0), "김민재", "hour - player name");

				assert.equal(rankingRecordManager.getRankAt(5), 6, "hour - rank");
				assert.equal(rankingRecordManager.getBestRecordAt(5), 87.64, "hour - best record");
				assert.equal(rankingRecordManager.getPlayerIDAt(5), 60, "hour - player ID");
				assert.equal(rankingRecordManager.getPlayerNameAt(5), "이서영", "hour - player name");

				done2();
			}
		);
	});


	// #3 Day 2018-08-23
	let date3 = "2018-08-23";
	let time3 = "16:53:00";

	let done3 = assert.async();
	setTimeout(function() {
		dbConnectManager.requestRanking(
			DBConnectManager.TYPE_MY_RANKING_DAY,
			sessionStorageManager.getMaestroID(),
			date3,
			time3,
			(type, rankingRecordManager) => {
				assert.equal(rankingRecordManager.getRankAt(0), 1, "day - rank #3");
				assert.equal(rankingRecordManager.getBestRecordAt(0), 99.18, "day - best record");
				assert.equal(rankingRecordManager.getPlayerIDAt(0), 46, "day - player ID");
				assert.equal(rankingRecordManager.getPlayerNameAt(0), "강예원", "day - player name");

				assert.equal(rankingRecordManager.getRankAt(5), 6, "day - rank");
				assert.equal(rankingRecordManager.getBestRecordAt(5), 94.48, "day - best record");
				assert.equal(rankingRecordManager.getPlayerIDAt(5), 57, "day - player ID");
				assert.equal(rankingRecordManager.getPlayerNameAt(5), "고울", "day - player name");

				done3();
			}
		);
	});


	// #3 Day 2019-08-23
	let date4 = "2019-08-23";
	let time4 = "16:53:00";

	let done4 = assert.async();
	setTimeout(function() {
		dbConnectManager.requestRanking(
			DBConnectManager.TYPE_MY_RANKING_MONTH,
			sessionStorageManager.getMaestroID(),
			date4,
			time4,
			(type, rankingRecordManager) => {
				assert.equal(rankingRecordManager.getCount(), 1, "month - rank");
				// assert.equal(rankingRecordManager.getRankAt(0), 1, "day - rank #3");
				// assert.equal(rankingRecordManager.getBestRecordAt(0), 99.18, "day - best record");
				// assert.equal(rankingRecordManager.getPlayerIDAt(0), 46, "day - player ID");
				// assert.equal(rankingRecordManager.getPlayerNameAt(0), "강예원", "day - player name");

				// assert.equal(rankingRecordManager.getRankAt(5), 6, "day - rank");
				// assert.equal(rankingRecordManager.getBestRecordAt(5), 94.48, "day - best record");
				// assert.equal(rankingRecordManager.getPlayerIDAt(5), 57, "day - player ID");
				// assert.equal(rankingRecordManager.getPlayerNameAt(5), "고울", "day - player name");

				done4();
			}
		);
	});
});


//////////////////////////////////////////////////
// AccountValidator

let accountValidator = new AccountValidator();

QUnit.test( "AccountValidator - isValidMaestroID", function( assert ) {
	let text = "";
	assert.equal(accountValidator.isValidMaestroID(text), false, "isValidMaestroID - no text");
	text = "1abcde";
	assert.equal(accountValidator.isValidMaestroID(text), false, "isValidMaestroID - " + text);
	text = "abc";
	assert.equal(accountValidator.isValidMaestroID(text), false, "isValidMaestroID - " + text);
	text = "a1b";
	assert.equal(accountValidator.isValidMaestroID(text), false, "isValidMaestroID - " + text);
	text = "abcdeabcdeabcdeabcdea";
	assert.equal(accountValidator.isValidMaestroID(text), false, "isValidMaestroID - " + text);

	text = "abcd";
	assert.equal(accountValidator.isValidMaestroID(text), true, "isValidMaestroID - " + text);
	text = "aA1Bccd";
	assert.equal(accountValidator.isValidMaestroID(text), true, "isValidMaestroID - " + text);
	text = "abcdeabcdeabcdeabcde";
	assert.equal(accountValidator.isValidMaestroID(text), true, "isValidMaestroID - " + text);
});

QUnit.test( "AccountValidator - isValidMaestroPW", function( assert ) {
	let text = "";
	assert.equal(accountValidator.isValidMaestroPW(text), false, "isValidMaestroPW - " + text);
	text = "1";
	assert.equal(accountValidator.isValidMaestroPW(text), false, "isValidMaestroPW - " + text);
	text = "12";
	assert.equal(accountValidator.isValidMaestroPW(text), false, "isValidMaestroPW - " + text);
	text = "123";
	assert.equal(accountValidator.isValidMaestroPW(text), false, "isValidMaestroPW - " + text);
	text = "1234";
	assert.equal(accountValidator.isValidMaestroPW(text), true, "isValidMaestroPW - " + text);
	text = "12345";
	assert.equal(accountValidator.isValidMaestroPW(text), true, "isValidMaestroPW - " + text);
	text = "123456";
	assert.equal(accountValidator.isValidMaestroPW(text), true, "isValidMaestroPW - " + text);
	text = "1234567891234567";
	assert.equal(accountValidator.isValidMaestroPW(text), true, "isValidMaestroPW - " + text);
	text = "12345678912345678";
	assert.equal(accountValidator.isValidMaestroPW(text), false, "isValidMaestroPW - " + text);

	text = "1abcde";
	assert.equal(accountValidator.isValidMaestroPW(text), true, "isValidMaestroPW - " + text);
	text = "abc";
	assert.equal(accountValidator.isValidMaestroPW(text), false, "isValidMaestroPW - " + text);
	text = "a1b";
	assert.equal(accountValidator.isValidMaestroPW(text), false, "isValidMaestroPW - " + text);
	text = "abcdeabcdeabcdeabcdea";
	assert.equal(accountValidator.isValidMaestroPW(text), false, "isValidMaestroPW - " + text);
	text = "abcdeabcdeabcdeabcde";
	assert.equal(accountValidator.isValidMaestroPW(text), false, "isValidMaestroPW - " + text);
});


QUnit.test( "AccountValidator - isValidPlayerID", function( assert ) {
	let text = "";
	assert.equal(accountValidator.isValidPlayerID(text), false, "isValidPlayerID - no text");
	text = "1abcde";
	assert.equal(accountValidator.isValidPlayerID(text), true, "isValidPlayerID - " + text);
	text = "abc";
	assert.equal(accountValidator.isValidPlayerID(text), true, "isValidPlayerID - " + text);
	text = "a1b";
	assert.equal(accountValidator.isValidPlayerID(text), true, "isValidPlayerID - " + text);
	text = "abcdeabcdeabcdeabcdea";
	assert.equal(accountValidator.isValidPlayerID(text), false, "isValidPlayerID - " + text);

	text = "abcd";
	assert.equal(accountValidator.isValidPlayerID(text), true, "isValidPlayerID - " + text);
	text = "aA1Bccd";
	assert.equal(accountValidator.isValidPlayerID(text), true, "isValidPlayerID - " + text);
	text = "abcdeabcdeabcdeabcde";
	assert.equal(accountValidator.isValidPlayerID(text), false, "isValidPlayerID - " + text);

	text = "박지상";
	assert.equal(accountValidator.isValidPlayerID(text), true, "isValidPlayerID - " + text);
	text = "박지상76";
	assert.equal(accountValidator.isValidPlayerID(text), true, "isValidPlayerID - " + text);
	text = "박";
	assert.equal(accountValidator.isValidPlayerID(text), true, "isValidPlayerID - " + text);
	text = "ㅂ";
	assert.equal(accountValidator.isValidPlayerID(text), false, "isValidPlayerID - " + text);

	text = "박지상박세나";
	assert.equal(accountValidator.isValidPlayerID(text), true, "isValidPlayerID - " + text);
	text = "박지상박세나신현";
	assert.equal(accountValidator.isValidPlayerID(text), true, "isValidPlayerID - " + text);
	text = "박지상박세나ab";
	assert.equal(accountValidator.isValidPlayerID(text), true, "isValidPlayerID - " + text);
	text = "박지상박세나abc";
	assert.equal(accountValidator.isValidPlayerID(text), false, "isValidPlayerID - " + text);
	text = "박지상박세나신현주";
	assert.equal(accountValidator.isValidPlayerID(text), false, "isValidPlayerID - " + text);
	text = "박지상박세나123";
	assert.equal(accountValidator.isValidPlayerID(text), false, "isValidPlayerID - " + text);

	text = "1-3박세나";
	assert.equal(accountValidator.isValidPlayerID(text), true, "isValidPlayerID - " + text);
	text = "1-4 박지상";
	assert.equal(accountValidator.isValidPlayerID(text), false, "isValidPlayerID - " + text);
});

QUnit.test( "AccountValidator - isValidPlayerPW", function( assert ) {
	let text = "";
	assert.equal(accountValidator.isValidPlayerPW(text), false, "isValidPlayerPW - " + text);
	text = "1";
	assert.equal(accountValidator.isValidPlayerPW(text), false, "isValidPlayerPW - " + text);
	text = "12";
	assert.equal(accountValidator.isValidPlayerPW(text), true, "isValidPlayerPW - " + text);
	text = "123";
	assert.equal(accountValidator.isValidPlayerPW(text), true, "isValidPlayerPW - " + text);
	text = "1234";
	assert.equal(accountValidator.isValidPlayerPW(text), true, "isValidPlayerPW - " + text);
	text = "12345";
	assert.equal(accountValidator.isValidPlayerPW(text), true, "isValidPlayerPW - " + text);
	text = "123456";
	assert.equal(accountValidator.isValidPlayerPW(text), true, "isValidPlayerPW - " + text);
	text = "1234567";
	assert.equal(accountValidator.isValidPlayerPW(text), true, "isValidPlayerPW - " + text);
	text = "12345678";
	assert.equal(accountValidator.isValidPlayerPW(text), true, "isValidPlayerPW - " + text);
	text = "123456789";
	assert.equal(accountValidator.isValidPlayerPW(text), false, "isValidPlayerPW - " + text);

	assert.equal(accountValidator.isValidPlayerPW(text), false, "isValidPlayerPW - no text");
	text = "1abcde";
	assert.equal(accountValidator.isValidPlayerPW(text), false, "isValidPlayerPW - " + text);
	text = "abc";
	assert.equal(accountValidator.isValidPlayerPW(text), false, "isValidPlayerPW - " + text);
	text = "a1b";
	assert.equal(accountValidator.isValidPlayerPW(text), false, "isValidPlayerPW - " + text);
	text = "abcdeabcdeabcdeabcdea";
	assert.equal(accountValidator.isValidPlayerPW(text), false, "isValidPlayerPW - " + text);

	text = "abcd";
	assert.equal(accountValidator.isValidPlayerPW(text), false, "isValidPlayerPW - " + text);
	text = "aA1Bccd";
	assert.equal(accountValidator.isValidPlayerPW(text), false, "isValidPlayerPW - " + text);
	text = "abcdeabcdeabcdeabcde";
	assert.equal(accountValidator.isValidPlayerPW(text), false, "isValidPlayerPW - " + text);
});



//////////////////////////////////////////////////
// TypingTextManager

let typingTextMan = new TypingTextManager();
let testContent = [ "ㅃ", "ㅂ", "ㅈ", "ㅉ", "ㄸ", "ㄷ", "ㄱ", "ㄲ", "ㅅ" ];

QUnit.test( "TypingTextManager - makeExaminationContents", function( assert ) {
	var sentences = [
		"냉면 / 김남천",
		"",
		"'냉면'이라는 말에 '평양'이 붙어서 '평양냉면'이라야 비로소 어울리는 격에 맞는 말이 되듯이 냉면은 평양에 있어 대표적인 음식이다. 언제부터 이 냉면이 평양에 들어왔으며 언제부터 냉면이 평안도 사람의 입에 가장 많이 기호에 맞는 음식물이 되었는지는 나 같은 무식쟁이에게는 알 수도 없고 또 알려고도 아니한다.",
		"가나다라마바사아자차카타파하가나다라마바사아자차카타파하가나다라마바사아자차카타파하가나다라마바사아자차카타파하가나다라마바사아자차카타파하가나다라마바사아자차카타파하"
	];
	typingTextMan.init();
	typingTextMan.makeExaminationContents(sentences);
	let contents = typingTextMan.getContents();
	// console.log(contents.length);

	assert.equal(contents[0], "냉면 / 김남천", "addTextArray - line 1");
	assert.equal(contents[1], "'냉면'이라는 말에 '평양'이 붙어서 '평양냉면'이라야 ", "addTextArray - line 2");
	assert.equal(contents[2], "비로소 어울리는 격에 맞는 말이 되듯이 냉면은 평양에 ", "addTextArray - line 3");
	assert.equal(contents[3], "있어 대표적인 음식이다. 언제부터 이 냉면이 평양에 ", "addTextArray - line 4");
	assert.equal(contents[8], "가나다라마바사아자차카타파하가나다라마바사아자차카타파하", "addTextArray - line 5");
	assert.equal(contents[9], "가나다라마바사아자차카타파하가나다라마바사아자차카타파하", "addTextArray - line 6");
});

QUnit.test( "TypingTextManager - add", function( assert ) {
	typingTextMan.init();
	typingTextMan.add(testContent);
	let contents = typingTextMan.getContents();

	assert.equal(contents[0], "ㅃ", "addTextArray - ㅃ");
	assert.equal(contents[8], "ㅅ", "addTextArray - ㅅ");

	typingTextMan.add([ "k", "l" ]);
	contents = typingTextMan.getContents();

	assert.equal(contents[9], "k", "addTextArray - k");
	assert.equal(contents[10], "l", "addTextArray - l");
});

QUnit.test( "TypingTextManager - slice", function( assert ) {
	typingTextMan.init();
	typingTextMan.add(testContent);
	typingTextMan.slice(0, 3);
	let contents = typingTextMan.getContents();

	assert.equal(contents[0], "ㅃ", "slice - ㅃ");
	assert.equal(contents[2], "ㅈ", "slice - ㅈ");
	assert.equal(contents[3], undefined, "slice - ㅉ");
});

QUnit.test( "TypingTextManager - makePracticeContents", function( assert ) {
	var repeatCount = 2;
	typingTextMan.makePracticeContents(testContent, repeatCount);
	let contents = typingTextMan.getContents();

	var countTestContent = testContent.length * (repeatCount + 1) * 2;
	// repeatCount + 1 : original list + (shuffled list * 2)
	// *2 : chosung + jungsung

	assert.equal(contents[0], "ㅃ", "makePracticeContents - ㅃ");
	assert.equal(contents[1], "ㅓ", "makePracticeContents - ㅓ");
	assert.equal(contents[(testContent.length - 1) * 2], "ㅅ", "makePracticeContents - ㅅ");
	assert.equal(contents.length, countTestContent, "makePracticeContents - length");
});

QUnit.test( "TypingTextManager - makeTestContents", function( assert ) {
	typingTextMan.makeTestContents(testContent);
	let contents = typingTextMan.getContents();

	assert.equal(contents.length, testContent.length, "makeTestContents - length");
});



//////////////////////////////////////////////////
// KeyMapper

let keyMapper = new KeyMapper();

QUnit.test( "KeyMapper - getNormalText", function( assert ) {
	assert.equal(keyMapper.getNormalText("Backquote"), "`", "getNormalText - `");
	assert.equal(keyMapper.getNormalText("Slash"), "/", "getNormalText - /");

	assert.equal(keyMapper.getNormalText("KeyQ", Keyboard.ENGLISH), "q", "getNormalText - q");
	assert.equal(keyMapper.getNormalText("KeyM", Keyboard.ENGLISH), "m", "getNormalText - m");

	assert.equal(keyMapper.getNormalText("KeyQ", Keyboard.KOREAN), "ㅂ", "getNormalText - ㅂ");
	assert.equal(keyMapper.getNormalText("KeyM", Keyboard.KOREAN), "ㅡ", "getNormalText - ㅡ");
});

QUnit.test( "KeyMapper - getShiftText", function( assert ) {
	assert.equal(keyMapper.getShiftText("Backquote"), "~", "getShiftText - ~");
	assert.equal(keyMapper.getShiftText("Slash"), "?", "getShiftText - ?");

	assert.equal(keyMapper.getShiftText("KeyQ", Keyboard.ENGLISH), "Q", "getShiftText - Q");
	assert.equal(keyMapper.getShiftText("KeyM", Keyboard.ENGLISH), "M", "getShiftText - M");

	assert.equal(keyMapper.getShiftText("KeyQ", Keyboard.KOREAN), "ㅃ", "getShiftText - ㅃ");
	assert.equal(keyMapper.getShiftText("KeyM", Keyboard.KOREAN), "ㅡ", "getShiftText - ㅡ");
});

/*
QUnit.test( "KeyMapper - getShiftHandSide", function( assert ) {
	assert.equal(keyMapper.getShiftHandSide("Backquote"), KeyTextData.RIGHT_HAND, "getShiftHandSide - `");
	assert.equal(keyMapper.getShiftHandSide("Slash"), KeyTextData.LEFT_HAND, "getShiftHandSide - /");

	assert.equal(keyMapper.getShiftHandSide("Space"), KeyTextData.BOTH_HAND, "getShiftHandSide - space");

	assert.equal(keyMapper.getShiftHandSide("KeyQ"), KeyTextData.RIGHT_HAND, "getShiftHandSide - q");
	assert.equal(keyMapper.getShiftHandSide("KeyM"), KeyTextData.LEFT_HAND, "getShiftHandSide - m");

	assert.equal(keyMapper.getShiftHandSide("KeyQ", Keyboard.KOREAN), KeyTextData.RIGHT_HAND, "getShiftHandSide - q");
	assert.equal(keyMapper.getShiftHandSide("KeyM", Keyboard.KOREAN), KeyTextData.LEFT_HAND, "getShiftHandSide - m");
});
*/



QUnit.test( "KeyMapper - getKeyIDOfText", function( assert ) {
	assert.equal(keyMapper.getKeyIDOfText("`"), "Backquote", "getKeyIDOfText - `");
	assert.equal(keyMapper.getKeyIDOfText("~"), "Backquote", "getKeyIDOfText - ~");
	assert.equal(keyMapper.getKeyIDOfText("/"), "Slash", "getKeyIDOfText - /");
	assert.equal(keyMapper.getKeyIDOfText("?"), "Slash", "getKeyIDOfText - ?");

	assert.equal(keyMapper.getKeyIDOfText("q"), "KeyQ", "getKeyIDOfText - q");
	assert.equal(keyMapper.getKeyIDOfText("Q"), "KeyQ", "getKeyIDOfText - Q");
	assert.equal(keyMapper.getKeyIDOfText("m"), "KeyM", "getKeyIDOfText - m");
	assert.equal(keyMapper.getKeyIDOfText("M"), "KeyM", "getKeyIDOfText - M");

	assert.equal(keyMapper.getKeyIDOfText("ㅂ"), "KeyQ", "getKeyIDOfText - ㅂ");
	assert.equal(keyMapper.getKeyIDOfText("ㅃ"), "KeyQ", "getKeyIDOfText - ㅃ");
	assert.equal(keyMapper.getKeyIDOfText("ㅡ"), "KeyM", "getKeyIDOfText - ㅡ");

	assert.equal(keyMapper.getKeyIDOfText("Backspace"), "Backspace", "getKeyIDOfText - ㅂ");
});

QUnit.test( "KeyMapper - isShiftText", function( assert ) {
	assert.equal(keyMapper.isShiftText("`"), false, "isShiftText - `");
	assert.equal(keyMapper.isShiftText("~"), true, "isShiftText - ~");
	assert.equal(keyMapper.isShiftText("/"), false, "isShiftText - /");
	assert.equal(keyMapper.isShiftText("?"), true, "isShiftText - ?");

	assert.equal(keyMapper.isShiftText("q"), false, "isShiftText - q");
	assert.equal(keyMapper.isShiftText("Q"), true, "isShiftText - Q");
	assert.equal(keyMapper.isShiftText("m"), false, "isShiftText - m");
	assert.equal(keyMapper.isShiftText("M"), true, "isShiftText - M");

	assert.equal(keyMapper.isShiftText("ㅁ"), false, "isShiftText - ㅁ");
	assert.equal(keyMapper.isShiftText("ㄴ"), false, "isShiftText - ㄴ");
	assert.equal(keyMapper.isShiftText("ㅇ"), false, "isShiftText - ㅇ");

	assert.equal(keyMapper.isShiftText("ㅂ"), false, "isShiftText - ㅂ");
	assert.equal(keyMapper.isShiftText("ㅃ"), true, "isShiftText - ㅃ");
	assert.equal(keyMapper.isShiftText("ㅡ"), false, "isShiftText - ㅡ");
});



//////////////////////////////////////////////////
// DBConnectManager

let dbConnectManager = new DBConnectManager();
dbConnectManager.setMaestroID(0);
dbConnectManager.setPlayerID(0);
dbConnectManager.setDateTime("2018-05-16", "14:50:00");

QUnit.test( "DBConnectManager - Player login", function( assert ) {
	let returnPlayerID = -1;

	let done = assert.async();
	setTimeout(function() {
		dbConnectManager.requestCheckPlayerLogin(
			"jisangs", "test", "111111",
			(jsonData) => {
				returnPlayerID = jsonData["PlayerID"];
				assert.equal(returnPlayerID, 300);
				done();
			},
			(jsonData) => {
				console.log(jsonData);
				done();
			}
		);
	});
});

// DB data is not prepared
/*
QUnit.test( "DBConnectManager - Player history", function( assert ) {
	sessionStorageManager.maestroID = 1;	// jisangs
	sessionStorageManager.playerID = "8";	// 부현율
	sessionStorageManager.playingAppID = 29;
	let date = "2018-05-16";

	let done = assert.async();
	setTimeout(function() {
		dbConnectManager.requestPlayerHistory(
			1,	// maestroID for jisangs
			date,
			(historyRecordManager) => {
				// console.log(historyRecordManager);

				assert.equal(historyRecordManager.getAppNameAt(0), "test_korean_word");
				assert.equal(historyRecordManager.getDateAt(0), "2018-05-16");
				assert.equal(historyRecordManager.getBestRecordAt(0), 108.248);

				assert.equal(historyRecordManager.getAppNameAt(4), "test_korean_word");
				assert.equal(historyRecordManager.getDateAt(4), "2018-04-23");
				assert.equal(historyRecordManager.getBestRecordAt(4), 74.2234);

				done();
			}
		);
	});
});
*/

QUnit.test( "DBConnectManager - HowToPlay", function( assert ) {
	let howToPlayForSpaceInvaders = "외계인이 나타났다!\\n마우스 왼쪽 버튼을 클릭해서\\n외계인이 사라지기 전에 물리쳐 주세요.";
	var howToPlayForTyping = "왼손 검지를 [F] 자판위에,\\n오른손 검지를 [J] 자판위에 올린채\\n손을 움직이지 말고 글자를 입력하세요.";

	let done = assert.async(2);

	setTimeout(function() {
		dbConnectManager.requestHowToPlay(
			101,	// space_invaders app ID
			(jsonData) => {
				let howToPlay = jsonData["HowToPlay"];
				assert.equal(howToPlay, howToPlayForSpaceInvaders);
				done();
			},
			(jsonData) => {
				console.log(jsonData);
				done();
			}
		);

		dbConnectManager.requestHowToPlay(
			1,	// korean basic typing
			(jsonData) => {
				let howToPlay = jsonData["HowToPlay"];
				assert.equal(howToPlay, howToPlayForTyping);
				done();
			},
			(jsonData) => {
				console.log(jsonData);
				done();
			}
		);
	});
});

// DB data is not prepared
/*
QUnit.test( "DBConnectManager - UpdateRecord", function( assert ) {
	let todayBestRecord = 0;

	let done = assert.async();

	setTimeout(function() {
		dbConnectManager.requestTodayBestRecord(
			1,	// maestro ID for "jisangs"
			1,	// Player ID for jisangs
			101,	// space_invaders app ID
			(jsonData) => {
				todayBestRecord = jsonData["BestRecord"];
			},
			(jsonData) => {
				console.log(jsonData);
				todayBestRecord = 0;
			}
		);
	});

	setTimeout(function() {
		dbConnectManager.updateTodayBestRecord(
			1,	// maestro ID for "jisangs"
			1,	// Player ID for jisangs
			101,	// space_invaders app ID
			todayBestRecord + 1000	// new record
		);
	}, 100);

	setTimeout(function() {
		dbConnectManager.requestTodayBestRecord(
			1,	// maestro ID for "jisangs"
			1,	// Player ID for jisangs
			101,	// space_invaders app ID
			(jsonData) => {
				let bestRecord = jsonData["BestRecord"];
				assert.equal(bestRecord, todayBestRecord + 1000);
				done();
			},
			(jsonData) => {
				console.log(jsonData);
				done();
			}
		);
	}, 200);
});
*/


//////////////////////////////////////////////////
// HeartManager

let heartManager = new HeartManager();

QUnit.test( "HeartManager - MaxCount", function( assert ) {
	heartManager.setCount(3);
	assert.equal(heartManager.getCount(), 3);

	heartManager.setMaxCount(5);
	assert.equal(heartManager.getCount(), 3);

	heartManager.setMaxCount(3);
	assert.equal(heartManager.getCount(), 3);

	heartManager.setMaxCount(2);
	assert.equal(heartManager.getCount(), 2);
});


QUnit.test( "HeartManager - setCount", function( assert ) {
	heartManager.setMaxCount(3);

	heartManager.setCount(3);
	assert.equal(heartManager.getCount(), 3);

	heartManager.setCount(2);
	assert.equal(heartManager.getCount(), 2);
});


QUnit.test( "HeartManager - addHearts", function( assert ) {
	heartManager.setMaxCount(3);

	heartManager.setCount(1);
	assert.equal(heartManager.getCount(), 1);

	heartManager.addHearts(1);
	assert.equal(heartManager.getCount(), 2);

	heartManager.setCount(1);
	assert.equal(heartManager.getCount(), 1);

	heartManager.addHearts(2);
	assert.equal(heartManager.getCount(), 3);

	heartManager.setCount(1);
	assert.equal(heartManager.getCount(), 1);

	heartManager.addHearts(3);
	assert.equal(heartManager.getCount(), 3);
});


QUnit.test( "HeartManager - breakHearts", function( assert ) {
	heartManager.setMaxCount(3);

	heartManager.setCount(3);
	assert.equal(heartManager.getCount(), 3);

	heartManager.breakHearts(1);
	assert.equal(heartManager.getCount(), 2);

	heartManager.breakHearts(2);
	assert.equal(heartManager.getCount(), 0);
});


//////////////////////////////////////////////////
// HistoryRecordManager

let historyRecordManager = new HistoryRecordManager();

historyRecordManager.push(new HistoryRecord("05/10", "space_invaders", 1000));
historyRecordManager.push(new HistoryRecord("05/11", "typing_korean_basic", 100));
historyRecordManager.push(new HistoryRecord("05/12", "cooking_meats", 200));
historyRecordManager.push(new HistoryRecord("05/13", "typing_english_basic", 2000));
historyRecordManager.push(new HistoryRecord("05/14", "test", 10000));

QUnit.test( "HistoryRecordManager - push", function( assert ) {
	assert.equal(historyRecordManager.historyRecords.length, 5);
});

QUnit.test( "HistoryRecordManager - getAt", function( assert ) {
	assert.equal(historyRecordManager.getDateAt(0), "05/10");
	assert.equal(historyRecordManager.getDateAt(4), "05/14");

	assert.equal(historyRecordManager.getAppNameAt(0), "space_invaders");
	assert.equal(historyRecordManager.getAppNameAt(4), "test");
});

QUnit.test( "HistoryRecordManager - clear", function( assert ) {
	let historyRecordManagerForClear = new HistoryRecordManager();
	historyRecordManagerForClear.push(new HistoryRecord("05/10", "space_invaders", 1));
	historyRecordManagerForClear.clear();

	assert.equal(historyRecordManagerForClear.historyRecords.length, 0);
});

QUnit.test( "HistoryRecordManager - underValueForGraph", function( assert ) {
	assert.equal(historyRecordManager.underValueForGraph(), 100);
});

QUnit.test( "HistoryRecordManager - upperValueForGraph", function( assert ) {
	assert.equal(historyRecordManager.upperValueForGraph(), 10000);
});



//////////////////////////////////////////////////
// NumberUtil

QUnit.test( "NumberUtil - NumberWithCommas", function( assert ) {
	assert.equal(NumberUtil.numberWithCommas(1), "1", "NumberWithCommas");
	assert.equal(NumberUtil.numberWithCommas(1000), "1,000", "NumberWithCommas");
	assert.equal(NumberUtil.numberWithCommas(100000), "100,000", "NumberWithCommas");
	assert.equal(NumberUtil.numberWithCommas(1000000), "1,000,000", "NumberWithCommas");
});

QUnit.test( "NumberUtil - NumberOfDigits", function( assert ) {
	assert.equal(NumberUtil.numberOfDigits(1), 1);
	assert.equal(NumberUtil.numberOfDigits(10), 2);
	assert.equal(NumberUtil.numberOfDigits(100), 3);
	assert.equal(NumberUtil.numberOfDigits(999), 3);
	assert.equal(NumberUtil.numberOfDigits(1000), 4);
	assert.equal(NumberUtil.numberOfDigits(9999), 4);
	assert.equal(NumberUtil.numberOfDigits(10000), 5);
	assert.equal(NumberUtil.numberOfDigits(99999), 5);
});


//////////////////////////////////////////////////
// RankingRecordManager

let rankingRecordManager = new RankingRecordManager();

rankingRecordManager.push(new RankingRecord(4, 1, "김남희", 1400));
rankingRecordManager.push(new RankingRecord(5, 2, "고봉순", 900));
rankingRecordManager.push(new RankingRecord(6, 3, "파르마", 800));
rankingRecordManager.push(new RankingRecord(7, 4, "박지상", 700));
rankingRecordManager.push(new RankingRecord(8, 5, "신현주", 600));

QUnit.test( "RankingRecordManager - push", function( assert ) {
	assert.equal(rankingRecordManager.rankingRecords.length, 5);
});

QUnit.test( "RankingRecordManager - getAt", function( assert ) {
	assert.equal(rankingRecordManager.getRankAt(0), 4);
	assert.equal(rankingRecordManager.getRankAt(4), 8);

	assert.equal(rankingRecordManager.getPlayerIDAt(0), 1);
	assert.equal(rankingRecordManager.getPlayerIDAt(4), 5);

	assert.equal(rankingRecordManager.getPlayerNameAt(0), "김남희");
	assert.equal(rankingRecordManager.getPlayerNameAt(4), "신현주");

	assert.equal(rankingRecordManager.getBestRecordAt(0), 1400);
	assert.equal(rankingRecordManager.getBestRecordAt(4), 600);
});

QUnit.test( "RankingRecordManager - clear", function( assert ) {
	let rankingRecordManagerForClear = new RankingRecordManager();
	rankingRecordManagerForClear.push(new RankingRecord(8, "신현주", 600));
	rankingRecordManagerForClear.clear();

	assert.equal(rankingRecordManagerForClear.rankingRecords.length, 0);
});


//////////////////////////////////////////////////
// ScoreManager

let scoreManager = new ScoreManager();

QUnit.test( "ScoreManager - plusScore", function( assert ) {
	assert.equal(scoreManager.score, 0);
	scoreManager.plusScore(10);
	assert.equal(scoreManager.score, 10);
	scoreManager.minusScore(10);
	assert.equal(scoreManager.score, 0);
});


//////////////////////////////////////////////////
// SessionStorageManager

QUnit.test( "SessionStorageManager - PlayerName", function( assert ) {
	sessionStorageManager.clear();
	assert.equal(sessionStorageManager.getPlayerName(), null, "playerName");

	sessionStorageManager.setPlayerName("박지상");
	assert.equal(sessionStorageManager.getPlayerName(), "박지상", "playerName");

	sessionStorageManager.removeItem("playerName");
	assert.equal(sessionStorageManager.getPlayerName(), null, "playerName");
});

QUnit.test( "SessionStorageManager - playerPlayerID", function( assert ) {
	sessionStorageManager.clear();
	assert.equal(sessionStorageManager.getPlayerID(), null, "playerID");

	sessionStorageManager.setPlayerID(1);
	assert.equal(sessionStorageManager.getPlayerID(), 1, "playerID");

	sessionStorageManager.removeItem("playerID");
	assert.equal(sessionStorageManager.getPlayerID(), null, "playerID");
});

QUnit.test( "SessionStorageManager - playingAppName", function( assert ) {
	sessionStorageManager.clear();
	assert.equal(sessionStorageManager.getPlayingAppName(), null, "playingAppName");

	sessionStorageManager.setPlayingAppName("space_invaders");
	assert.equal(sessionStorageManager.getPlayingAppName(), "space_invaders", "playingAppName");

	sessionStorageManager.removeItem("playingAppName");
	assert.equal(sessionStorageManager.getPlayingAppName(), null, "playingAppName");
});



//////////////////////////////////////////////////
// test

QUnit.test( "hello test", function( assert ) {
  assert.ok( 1 == "1", "Passed!" );
});