test: main model
This commit is contained in:
		
							parent
							
								
									f721cee708
								
							
						
					
					
						commit
						859d34e3bb
					
				
					 5 changed files with 114 additions and 13 deletions
				
			
		| 
						 | 
					@ -3,26 +3,31 @@
 | 
				
			||||||
		public int Score { private set; get; }
 | 
							public int Score { private set; get; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public readonly int SpawnRate;
 | 
							public readonly int SpawnRate;
 | 
				
			||||||
		private bool _needsToSpawn;
 | 
							public readonly int GrowIterations;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public Model(int spawnRate) : this(0, spawnRate) { }
 | 
							public float GrowPercentage { private set; get; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public Model(int score, int spawnRate) {
 | 
							public bool NeedsToSpawn { private set; get; }
 | 
				
			||||||
 | 
							public bool NeedsToAnimate { private set; get; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public Model(int spawnRate, int growIterations) : this(0, spawnRate, growIterations) { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public Model(int score, int spawnRate, int growIterations) {
 | 
				
			||||||
			Score = score;
 | 
								Score = score;
 | 
				
			||||||
			SpawnRate = spawnRate;
 | 
								SpawnRate = spawnRate;
 | 
				
			||||||
 | 
								GrowIterations = growIterations;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public void AddScore() {
 | 
							public void AddScore() {
 | 
				
			||||||
			Score++;
 | 
								Score++;
 | 
				
			||||||
			if (Score % SpawnRate == 0)
 | 
								NeedsToAnimate = NeedsToSpawn = false;
 | 
				
			||||||
				_needsToSpawn = true;
 | 
					
 | 
				
			||||||
 | 
								if (Score % GrowIterations == 0) {
 | 
				
			||||||
 | 
									GrowPercentage = Score / (float)(SpawnRate * GrowIterations);
 | 
				
			||||||
 | 
									NeedsToAnimate = true;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
								if (Score % (SpawnRate * GrowIterations) == 0)
 | 
				
			||||||
		public bool NeedsToSpawn() {
 | 
									NeedsToSpawn = true;
 | 
				
			||||||
			bool needs = _needsToSpawn;
 | 
					 | 
				
			||||||
			_needsToSpawn = false;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			return needs;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -16,7 +16,7 @@ namespace Presenter {
 | 
				
			||||||
			_model.AddScore();
 | 
								_model.AddScore();
 | 
				
			||||||
			_view.UpdateView(_model.Score);
 | 
								_view.UpdateView(_model.Score);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (_model.NeedsToSpawn()) {
 | 
								if (_model.NeedsToSpawn) {
 | 
				
			||||||
				_spawner.SpawnRose();
 | 
									_spawner.SpawnRose();
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										93
									
								
								Assets/Scripts/Tests/ModelTests.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										93
									
								
								Assets/Scripts/Tests/ModelTests.cs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,93 @@
 | 
				
			||||||
 | 
					using Domain;
 | 
				
			||||||
 | 
					using NUnit.Framework;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Tests {
 | 
				
			||||||
 | 
						public class ModelTests {
 | 
				
			||||||
 | 
							[Test]
 | 
				
			||||||
 | 
							public void NoPress_NoAnimation() {
 | 
				
			||||||
 | 
								Model sut = new(20, 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								Assert.IsFalse(sut.NeedsToAnimate);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Test]
 | 
				
			||||||
 | 
							public void NotEnoughPresses_NoAnimation() {
 | 
				
			||||||
 | 
								Model sut = new(20, 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sut.AddScore();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								Assert.IsFalse(sut.NeedsToAnimate);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Test]
 | 
				
			||||||
 | 
							public void EnoughPresses_Animation() {
 | 
				
			||||||
 | 
								Model sut = new(20, 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								for (int i = 0; i < 5; i++)
 | 
				
			||||||
 | 
									sut.AddScore();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								Assert.IsTrue(sut.NeedsToAnimate);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Test]
 | 
				
			||||||
 | 
							public void NoPress_NoSpawn() {
 | 
				
			||||||
 | 
								Model sut = new(20, 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								Assert.IsFalse(sut.NeedsToSpawn);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Test]
 | 
				
			||||||
 | 
							public void NotEnoughPresses_NoSpawn() {
 | 
				
			||||||
 | 
								Model sut = new(20, 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								sut.AddScore();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								Assert.IsFalse(sut.NeedsToSpawn);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Test]
 | 
				
			||||||
 | 
							public void EnoughPresses_Spawn() {
 | 
				
			||||||
 | 
								Model sut = new(20, 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								for (int i = 0; i < 20 * 5; i++) {
 | 
				
			||||||
 | 
									sut.AddScore();
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								Assert.IsTrue(sut.NeedsToSpawn);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Test]
 | 
				
			||||||
 | 
							public void OneIteration_UpdatesGrowPercentage() {
 | 
				
			||||||
 | 
								Model sut = new(5, 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								for (int i = 0; i < 5; i++) {
 | 
				
			||||||
 | 
									sut.AddScore();
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								Assert.AreEqual(1f / 5f, sut.GrowPercentage);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Test]
 | 
				
			||||||
 | 
							public void AllIterations_GrowCompleted() {
 | 
				
			||||||
 | 
								Model sut = new(5, 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								for (int i = 0; i < 5 * 5; i++) {
 | 
				
			||||||
 | 
									sut.AddScore();
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								Assert.AreEqual(1f, sut.GrowPercentage);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Test]
 | 
				
			||||||
 | 
							public void MoreIterations_ResetsGrowPercentage() {
 | 
				
			||||||
 | 
								Model sut = new(5, 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								for (int i = 0; i < 6 * 5; i++) {
 | 
				
			||||||
 | 
									sut.AddScore();
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								Assert.AreEqual(1f / 5f, sut.GrowPercentage);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										3
									
								
								Assets/Scripts/Tests/ModelTests.cs.meta
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								Assets/Scripts/Tests/ModelTests.cs.meta
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,3 @@
 | 
				
			||||||
 | 
					fileFormatVersion: 2
 | 
				
			||||||
 | 
					guid: b81eb0f05b9b4ed38c6b881421132fdd
 | 
				
			||||||
 | 
					timeCreated: 1713269019
 | 
				
			||||||
| 
						 | 
					@ -11,7 +11,7 @@ namespace View {
 | 
				
			||||||
		public CustomInput CustomInput { private set; get; }
 | 
							public CustomInput CustomInput { private set; get; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		private void Awake() {
 | 
							private void Awake() {
 | 
				
			||||||
			Model = new Model(20);
 | 
								Model = new Model(20, 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			IExpressionInput input = FindObjectOfType<ExpressionInput>();
 | 
								IExpressionInput input = FindObjectOfType<ExpressionInput>();
 | 
				
			||||||
			IExpressionInput visibility = FindObjectOfType<UIVisibility>();
 | 
								IExpressionInput visibility = FindObjectOfType<UIVisibility>();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue