Commit 5d470a57 authored by Gerard Gascón's avatar Gerard Gascón
Browse files

refactor: renamed Model.cs to Score.cs

parent 2be3b572
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
namespace Domain {
	public class Model {
		public int Score { private set; get; }
	public class Score {
		public int Value { private set; get; }

		public readonly int SpawnRate;
		public readonly int GrowIterations;

		public float GrowPercentage { private set; get; }

		public Model(int spawnRate, int growIterations) : this(0, spawnRate, growIterations) { }
		public Score(int spawnRate, int growIterations) : this(0, spawnRate, growIterations) { }

		public Model(int score, int spawnRate, int growIterations) {
			Score = score;
		public Score(int value, int spawnRate, int growIterations) {
			Value = value;
			SpawnRate = spawnRate;
			GrowIterations = growIterations;
		}

		public void AddScore() {
			Score++;
		public void Add() {
			Value++;

			if (Score % GrowIterations == 0) {
				float relativeScore = Score % (GrowIterations * SpawnRate);
				if (relativeScore == 0 && Score != 0)
			if (Value % GrowIterations == 0) {
				float relativeScore = Value % (GrowIterations * SpawnRate);
				if (relativeScore == 0 && Value != 0)
					relativeScore = GrowIterations * SpawnRate;
				GrowPercentage = relativeScore / (SpawnRate * GrowIterations);
			}
+6 −6
Original line number Diff line number Diff line
@@ -2,21 +2,21 @@

namespace Presenter {
	public class ExpressionClick {
		private readonly Model _model;
		private readonly Score _score;
		private readonly IExpressionInput _view;
		private readonly IRoseSpawner _spawner;

		private bool CanSpawn => _model.Score % (_model.GrowIterations * _model.SpawnRate) == 0;
		private bool CanSpawn => _score.Value % (_score.GrowIterations * _score.SpawnRate) == 0;

		public ExpressionClick(Model model, IExpressionInput view, IRoseSpawner spawner) {
			_model = model;
		public ExpressionClick(Score score, IExpressionInput view, IRoseSpawner spawner) {
			_score = score;
			_view = view;
			_spawner = spawner;
		}

		public void Execute() {
			_model.AddScore();
			_view.UpdateView(_model.Score);
			_score.Add();
			_view.UpdateView(_score.Value);

			if (CanSpawn)
				_spawner.SpawnRose();
+7 −7
Original line number Diff line number Diff line
@@ -2,13 +2,13 @@
using NUnit.Framework;

namespace Tests {
	public class ModelTests {
	public class ScoreTests {
		[Test]
		public void OneIteration_UpdatesGrowPercentage() {
			Model sut = new(5, 5);
			Score sut = new(5, 5);

			for (int i = 0; i < 5; i++) {
				sut.AddScore();
				sut.Add();
			}

			Assert.AreEqual(1f / 5f, sut.GrowPercentage);
@@ -16,10 +16,10 @@ namespace Tests {

		[Test]
		public void AllIterations_GrowCompleted() {
			Model sut = new(5, 5);
			Score sut = new(5, 5);

			for (int i = 0; i < 5 * 5; i++) {
				sut.AddScore();
				sut.Add();
			}

			Assert.AreEqual(1f, sut.GrowPercentage);
@@ -27,10 +27,10 @@ namespace Tests {

		[Test]
		public void MoreIterations_ResetsGrowPercentage() {
			Model sut = new(5, 5);
			Score sut = new(5, 5);

			for (int i = 0; i < 6 * 5; i++) {
				sut.AddScore();
				sut.Add();
			}

			Assert.AreEqual(1f / 5f, sut.GrowPercentage);
Loading