public void UpdateTrialCycleCheckpoint()
		{
			AnagramModel model = new AnagramModel();
			model.progress.level = model.tutorLevel;
			Assert.AreEqual(false, model.IsTutor(), "tutor");
			model.trialPeriod = 3;
			Assert.AreEqual(false, model.UpdateTrialCycleCheckpoint(), DescribeTrialCycle(model));
			Assert.AreEqual(false, model.isContinueVisible, "Is continue visible");
			model.trialCount = 0;
			Assert.AreEqual(false, model.UpdateTrialCycleCheckpoint(), DescribeTrialCycle(model));
			Assert.AreEqual(false, model.isContinueVisible, "Is continue visible");
			model.trialCount = 1;
			Assert.AreEqual(false, model.UpdateTrialCycleCheckpoint(), DescribeTrialCycle(model));
			Assert.AreEqual(false, model.isContinueVisible, "Is continue visible");
			model.trialCount = 2;
			Assert.AreEqual(false, model.UpdateTrialCycleCheckpoint(), DescribeTrialCycle(model));
			Assert.AreEqual(false, model.isContinueVisible, "Is continue visible");
			model.trialCount = 3;
			Assert.AreEqual(true, model.UpdateTrialCycleCheckpoint(), DescribeTrialCycle(model));
			Assert.AreEqual(true, model.isContinueVisible, "Is continue visible");
			model.isContinueVisible = false;
			model.trialCount = 4;
			Assert.AreEqual(false, model.UpdateTrialCycleCheckpoint(), DescribeTrialCycle(model));
			Assert.AreEqual(false, model.isContinueVisible, "Is continue visible");
		}
		public void RecordAndPlayback()
		{
			AnagramModel model = new AnagramModel();
			AssertRecordSubmitAndNewGame(model);
			model.journal.StartPlayback();
			AssertPlaybackSubmitAndNewGame(model);
			model.journal.isPlayback = false;
		}
 private static void LoadWords(AnagramModel model)
 {
     string text = StringUtil.Read("text/anagram_words.txt");
     string[] words = StringUtil.Split(text, StringUtil.lineDelimiter);
     AddWords(model.levels.parameters, words);
     string[] win = new string[]{"YOU", "WIN"};
     AddWords(model.levels.parameters, win);
 }
		public void WriteAndRead()
		{
			AnagramModel model = new AnagramModel();
			AssertRecordSubmitAndNewGame(model);
			string historyTsv = "delay\taction\n50\tnewGame\n33\tsubmit";
			Assert.AreEqual(historyTsv, model.journal.Write());
			model.journal.ReadAndPlay(historyTsv);
			AssertPlaybackSubmitAndNewGame(model);
		}
		public void IsTrialCycleNowTutorial()
		{
			AnagramModel model = new AnagramModel();
			Assert.AreEqual(true, model.IsTutor(), "tutor");
			model.trialPeriod = 5;
			Assert.AreEqual(false, model.IsTrialCycleNow(), DescribeTrialCycle(model));
			model.trialCount = 4;
			Assert.AreEqual(false, model.IsTrialCycleNow(), DescribeTrialCycle(model));
			model.trialCount = 5;
			Assert.AreEqual(true, model.IsTrialCycleNow(), DescribeTrialCycle(model));
			model.trialCount = 9;
			Assert.AreEqual(false, model.IsTrialCycleNow(), DescribeTrialCycle(model));
			model.trialCount = 10;
			Assert.AreEqual(true, model.IsTrialCycleNow(), DescribeTrialCycle(model));
		}
		public void UpdateHelpStateNowRepeat()
		{
			AnagramModel model = new AnagramModel();
			model.Update(0.0f);
			Assert.AreEqual(null, model.helpStateNow);
			model.helpTextNow.next = "WORD REPEATED";
			model.helpState.next = "repeat";
			model.Update(0.0f);
			Assert.AreEqual("beginNow", model.helpStateNow);
			model.Update(0.0f);
			Assert.AreEqual(null, model.helpStateNow);
			model.helpTextNow.next = "";
			model.helpState.next = "";
			model.Update(0.0f);
			Assert.AreEqual("endNow", model.helpStateNow);
			model.Update(0.0f);
			Assert.AreEqual(null, model.helpStateNow);
		}
		private void AssertPlaybackSubmitAndNewGame(AnagramModel model)
		{
			model.Setup();
			Assert.AreEqual(null, model.state);
			Assert.AreEqual(true, model.isNewGameVisible);
			model.Update(1.0f / 60.0f);
			model.Update(1.0f / 60.0f);
			model.Update(1.0f / 60.0f);
			Assert.AreEqual("newGame", model.journal.action);
			Assert.AreEqual("newGame", model.journal.actionNow);
			Assert.AreEqual("newGame", model.journal.commandNow);
			Assert.AreEqual(50, model.journal.milliseconds);
			Assert.AreEqual(false, model.isNewGameVisible);
			model.Update(1.0f / 60.0f);
			Assert.AreEqual(null, model.journal.actionNow);
			model.Update(1.0f / 60.0f);
			Assert.AreEqual("wrong", model.state);
			Assert.AreEqual("submit", model.journal.action);
			Assert.AreEqual("submit", model.journal.actionNow);
			Assert.AreEqual("submit", model.journal.commandNow);
			Assert.AreEqual(33, model.journal.milliseconds);
		}
		public void IsTrialCycleNow()
		{
			AnagramModel model = new AnagramModel();
			model.progress.level = model.tutorLevel;
			Assert.AreEqual(false, model.IsTutor(), "tutor");
			model.trialPeriod = 10;
			Assert.AreEqual(false, model.IsTrialCycleNow(), DescribeTrialCycle(model));
			model.trialCount = 5;
			Assert.AreEqual(false, model.IsTrialCycleNow(), DescribeTrialCycle(model));
			model.trialCount = 9;
			Assert.AreEqual(false, model.IsTrialCycleNow(), DescribeTrialCycle(model));
			model.trialCount = 10;
			Assert.AreEqual(true, model.IsTrialCycleNow(), DescribeTrialCycle(model));
			model.trialCount = 11;
			Assert.AreEqual(false, model.IsTrialCycleNow(), DescribeTrialCycle(model));
			model.trialCount = 19;
			Assert.AreEqual(false, model.IsTrialCycleNow(), DescribeTrialCycle(model));
			model.trialCount = 20;
			Assert.AreEqual(true, model.IsTrialCycleNow(), DescribeTrialCycle(model));
			model.trialCount = 21;
			Assert.AreEqual(false, model.IsTrialCycleNow(), DescribeTrialCycle(model));
		}
		private void AssertPlaybackActionEqualsCommand(
				AnagramModel model, string filePath)
		{
			string historyTsv = File.ReadAllText(filePath);
			model.Setup();
			model.journal.ReadAndPlay(historyTsv);
			float time = 0.0f;
			float step = 1.0f / 60.0f;
			float recorded = (float)(
				model.journal.playbackDelays.Sum()) / 1000.0f;
			string message = "file " + filePath;
			while (model.journal.IsPlaying())
			{
				time += step;
				model.Update(step);
				message = "file " + filePath
					+ " playback index " + model.journal.playbackIndex
					+ " word " + model.text;
				Assert.AreEqual(model.journal.commandNow,
					model.journal.actionNow, message);
			}
			float difference = Mathf.Abs(time - recorded);
			message = "file " + filePath
				+ " playback " + time.ToString() 
				+ " record " + recorded.ToString() 
				+ " difference " + difference;
			Assert.AreEqual(true, difference < 0.01f, message);
		}
		public void PlaybackActionEqualsCommand()
		{
			AnagramModel model = new AnagramModel();
			Words.Setup(model);
			AssertPlaybackActionEqualsCommand(model,
				"Assets/Scripts/Editor/Tests/test_journal.txt");
			model = new AnagramModel();
			Words.Setup(model);
			AssertPlaybackActionEqualsCommand(model,
				"Assets/Scripts/Editor/Tests/ethan_20160731_short.txt");
		}
		public void RecordSubmitAndNewGame()
		{
			AnagramModel model = new AnagramModel();
			AssertRecordSubmitAndNewGame(model);
		}
 public static void Setup(AnagramModel model)
 {
     LoadWords(model);
     model.wordHash = Read();
 }
		private static string DescribeTrialCycle(AnagramModel model)
		{
			return "trial count " + model.trialCount
				+ " in trial period " + model.trialPeriod;
		}
		public void UpdateIsHelpByPosition()
		{
			AnagramModel model = new AnagramModel();
			model.helpLevel = 100;
			model.helpPosition = 0.9f;
			model.width = 720.0f;
			model.Setup();
			model.progress.level = model.tutorLevel + 1;
			var parameters = new Dictionary<string, object>();
			parameters["text"] = "TALE";
			model.StartTrial(parameters);
			model.Update(0.5f);
			Assert.AreEqual("", model.helpTextNow.next);
			model.Update(0.5f);
			Assert.AreEqual(null, model.helpTextNow.next);
			model.Update(16.0f);
			string message = model.wordPositionMinNormal.ToString();
			Assert.AreEqual(model.shorterWordHelp, model.helpTextNow.next,
				message);
		}
		public void UpdateHelpStateNowEndOnce()
		{
			AnagramModel model = new AnagramModel();
			model.helpTextNow.next = "WORD REPEATED";
			model.helpState.next = "repeat";
			model.Update(0.0f);
			model.helpTextNow.next = "";
			model.helpState.next = "";
			model.Update(0.0f);
			Assert.AreEqual("endNow", model.helpStateNow);
			model.helpTextNow.next = "";
			model.helpState.next = "none";
			model.Update(0.0f);
			Assert.AreEqual("endNow", model.helpStateNow, "state from '' to 'none'");
		}
		public void IsHelpRepeatWhenHelpTextNull()
		{
			AnagramModel model = new AnagramModel();
			model.helpTextNow.next = null;
			Assert.AreEqual(true, model.IsHelpRepeat());
			model.progress.level = 100;
			Assert.AreEqual(false, model.IsHelpRepeat());
			model.progress.level = 10;
			Assert.AreEqual(true, model.IsHelpRepeat());
		}