24 changed files with 751 additions and 1 deletions
@ -0,0 +1,31 @@ |
|||
СЛОВО |
|||
БАСНЯ |
|||
АВЕРС |
|||
ТУМАН |
|||
БАРЖА |
|||
БИРЖА |
|||
АВЕРС |
|||
ТУМАН |
|||
БАРЖА |
|||
БИРЖА |
|||
АВЕРС |
|||
ТУМАН |
|||
БАРЖА |
|||
БИРЖА |
|||
АВЕРС |
|||
ТУМАН |
|||
БАРЖА |
|||
БИРЖА |
|||
АВЕРС |
|||
ТУМАН |
|||
БАРЖА |
|||
БИРЖА |
|||
АВЕРС |
|||
ТУМАН |
|||
БАРЖА |
|||
БИРЖА |
|||
АВЕРС |
|||
ТУМАН |
|||
БАРЖА |
|||
БИРЖА |
|||
ЗАМЕС |
|||
@ -0,0 +1,34 @@ |
|||
using FiveLetters.Model; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.Extensions.Logging; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace FiveLetters.Controllers |
|||
{ |
|||
[ApiController] |
|||
[Route("[controller]")]
|
|||
public class WeatherForecastController : ControllerBase |
|||
{ |
|||
private static readonly string[] Summaries = new[] |
|||
{ |
|||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" |
|||
}; |
|||
|
|||
private readonly ILogger<WeatherForecastController> _logger; |
|||
|
|||
public WeatherForecastController(ILogger<WeatherForecastController> logger) |
|||
{ |
|||
_logger = logger; |
|||
} |
|||
|
|||
[HttpGet] |
|||
public FiveLettersResult Get(string user) |
|||
{ |
|||
// TODO
|
|||
return new FiveLettersResult(user, String.Empty); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk.Web"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>net5.0</TargetFramework> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<None Update="202503.txt"> |
|||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
|||
</None> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,10 @@ |
|||
namespace FiveLetters.Model |
|||
{ |
|||
public enum EResultGameType |
|||
{ |
|||
None, |
|||
InProcess, |
|||
Finished, |
|||
Failed |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
namespace FiveLetters.Model |
|||
{ |
|||
public enum EResultLetterType |
|||
{ |
|||
None, |
|||
FullMatch, |
|||
PartialMatch |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
namespace FiveLetters.Model |
|||
{ |
|||
public class FileDictionaryProvider : IDictionaryProvider |
|||
{ |
|||
public bool CheckWordForExistence(string effectiveWord) |
|||
{ |
|||
// TODO IDictionaryProvider
|
|||
return true; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,67 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
|
|||
namespace FiveLetters.Model |
|||
{ |
|||
|
|||
|
|||
public class FileTaskProvider : ITaskProvider |
|||
{ |
|||
private List<FiveLettersTask> _tasks; |
|||
|
|||
public FileTaskProvider() |
|||
{ |
|||
_tasks = new List<FiveLettersTask>(); |
|||
} |
|||
|
|||
public FiveLettersTask GetTodayTask() |
|||
{ |
|||
var dd = DateTime.Now.Day; |
|||
if (_tasks.Count > dd) |
|||
{ |
|||
return _tasks[dd]; |
|||
} |
|||
else |
|||
{ |
|||
return _tasks[0]; |
|||
} |
|||
} |
|||
|
|||
private void h_LoadTasks() |
|||
{ |
|||
_tasks.Clear(); |
|||
DateTime dtStartMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); |
|||
string sFn = dtStartMonth.ToString("yyyyMM") + ".txt"; |
|||
if (File.Exists(sFn)) |
|||
{ |
|||
h_LoadTask(sFn, dtStartMonth); |
|||
} |
|||
else |
|||
{ |
|||
for (int ii = 0; ii < 31; ii++) |
|||
{ |
|||
_tasks.Add(new FiveLettersTask(dtStartMonth, "СЛОВО")); |
|||
dtStartMonth = dtStartMonth.AddDays(1); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private void h_LoadTask(string sFn, DateTime dtStartMonth) |
|||
{ |
|||
string[] lines = File.ReadAllLines(sFn); |
|||
for (int ii = 0; ii < lines.Length; ii++) |
|||
{ |
|||
_tasks.Add(new FiveLettersTask(dtStartMonth, lines[ii])); |
|||
dtStartMonth = dtStartMonth.AddDays(1); |
|||
} |
|||
} |
|||
|
|||
public FiveLettersTask GetTask(string taskGuid) |
|||
{ |
|||
return _tasks.FirstOrDefault(p => p.TaskGuid.Equals(taskGuid)); |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,98 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace FiveLetters.Model |
|||
{ |
|||
public class FiveLetterServer |
|||
{ |
|||
private readonly int MaxAttemptsCount = 6; |
|||
private readonly ITaskProvider _wordsProvider; |
|||
private readonly IDictionaryProvider _dictionaryProvider; |
|||
|
|||
Dictionary<string, List<FiveLettersResult>> Results { get; } |
|||
|
|||
public FiveLetterServer( |
|||
ITaskProvider wordsProvider, |
|||
IDictionaryProvider dictionaryProvider, |
|||
int attemptsCount = 0) |
|||
{ |
|||
if (attemptsCount > 0) |
|||
{ |
|||
MaxAttemptsCount = attemptsCount; |
|||
} |
|||
Results = new Dictionary<string, List<FiveLettersResult>>(); |
|||
this._wordsProvider = wordsProvider; |
|||
this._dictionaryProvider = dictionaryProvider; |
|||
|
|||
} |
|||
public FiveLettersResult Turn(string user, string word) |
|||
{ |
|||
FiveLettersResult result = GetResult(user); |
|||
string effectiveWord = word.Substring(0, 5); |
|||
// TODO: check by dictionary for word existence
|
|||
if (!_dictionaryProvider.CheckWordForExistence(effectiveWord)) |
|||
{ |
|||
return null; |
|||
} |
|||
var task = _wordsProvider.GetTask(result.TaskGuid); |
|||
h_PerformAnalyzeWordToTask(effectiveWord, task, result); |
|||
return result; |
|||
} |
|||
|
|||
public FiveLettersResult GetResult(string user) |
|||
{ |
|||
|
|||
if (!Results.ContainsKey(user)) |
|||
{ |
|||
Results[user] = new List<FiveLettersResult>(); |
|||
} |
|||
FiveLettersTask task = _wordsProvider.GetTodayTask(); |
|||
foreach (FiveLettersResult result in Results[user]) |
|||
{ |
|||
if (result.TaskGuid.Equals(task.TaskGuid)) |
|||
{ |
|||
// пользователь уже играет
|
|||
return result; |
|||
} |
|||
} |
|||
// пользователь еще не играет
|
|||
FiveLettersResult resultNew = new FiveLettersResult(user, task.TaskGuid); |
|||
resultNew.Result = EResultGameType.InProcess; |
|||
Results[user].Add(resultNew); |
|||
return resultNew; |
|||
} |
|||
|
|||
|
|||
private void h_PerformAnalyzeWordToTask(string word, FiveLettersTask task, FiveLettersResult result) |
|||
{ |
|||
List<FiveLettersItemLetterResult> letterResultAr = new List<FiveLettersItemLetterResult>(); |
|||
for (int ii = 0; ii < word.Length; ii++) |
|||
{ |
|||
char letter = (char)word[ii]; |
|||
if (letter.Equals(task.Word[ii])) |
|||
{ |
|||
letterResultAr.Add(new FiveLettersItemLetterResult(EResultLetterType.FullMatch, letter)); |
|||
} |
|||
else |
|||
{ |
|||
if (task.Word.Contains(letter)) |
|||
{ |
|||
letterResultAr.Add(new FiveLettersItemLetterResult(EResultLetterType.PartialMatch, letter)); |
|||
} |
|||
} |
|||
} |
|||
result.AddAttempt(letterResultAr); |
|||
if (word.Equals(task.Word)) |
|||
{ |
|||
result.Result = EResultGameType.Finished; |
|||
} |
|||
if (result.Attempts.Count >= MaxAttemptsCount) |
|||
{ |
|||
result.Result = EResultGameType.Failed; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
namespace FiveLetters.Model |
|||
{ |
|||
public class FiveLettersItemLetterResult |
|||
{ |
|||
public EResultLetterType Result { get; set; } |
|||
public char Letter { get; set; } |
|||
|
|||
public FiveLettersItemLetterResult(EResultLetterType result, char letter) |
|||
{ |
|||
Result = result; |
|||
Letter = letter; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace FiveLetters.Model |
|||
{ |
|||
public class FiveLettersItemResult |
|||
{ |
|||
public List<FiveLettersItemLetterResult> Results { get; set; } |
|||
|
|||
public FiveLettersItemResult(List<FiveLettersItemLetterResult> results) |
|||
{ |
|||
Results = results; |
|||
} |
|||
|
|||
public HashSet<char> GetLettersFullMatch() |
|||
{ |
|||
var hs = new HashSet<char>(); |
|||
foreach(var res in Results) |
|||
{ |
|||
if (res.Result == EResultLetterType.FullMatch) |
|||
{ |
|||
hs.Add(res.Letter); |
|||
} |
|||
} |
|||
return hs; |
|||
} |
|||
public HashSet<char> GetLettersPartialMatch() |
|||
{ |
|||
var hs = new HashSet<char>(); |
|||
foreach (var res in Results) |
|||
{ |
|||
if (res.Result == EResultLetterType.PartialMatch) |
|||
{ |
|||
hs.Add(res.Letter); |
|||
} |
|||
} |
|||
return hs; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,63 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace FiveLetters.Model |
|||
{ |
|||
public class FiveLettersResult |
|||
{ |
|||
|
|||
public DateTime DateStart { get; } |
|||
public string TaskGuid { get; } |
|||
public string User { get; } |
|||
public EResultGameType Result { get; set; } |
|||
public List<FiveLettersItemResult> Attempts { get; set; } |
|||
|
|||
public FiveLettersResult(string user, string taskGuid) |
|||
{ |
|||
Attempts = new List<FiveLettersItemResult>(); |
|||
User = user; |
|||
TaskGuid = taskGuid; |
|||
DateStart = DateTime.Now; |
|||
} |
|||
|
|||
internal void AddAttempt(List<FiveLettersItemLetterResult> result) |
|||
{ |
|||
var res = new FiveLettersItemResult(result); |
|||
if (Result != EResultGameType.InProcess) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
Attempts.Add(res); |
|||
} |
|||
|
|||
public HashSet<char> GetLettersFullMatch() |
|||
{ |
|||
HashSet<char> fm = new HashSet<char>(); |
|||
foreach (var att in Attempts) |
|||
{ |
|||
var attFm = att.GetLettersFullMatch(); |
|||
foreach (char ch in attFm) |
|||
{ |
|||
fm.Add(ch); |
|||
} |
|||
} |
|||
return fm; |
|||
} |
|||
|
|||
public HashSet<char> GetLettersPartialMatch() |
|||
{ |
|||
HashSet<char> fm = new HashSet<char>(); |
|||
foreach (var att in Attempts) |
|||
{ |
|||
var attFm = att.GetLettersPartialMatch(); |
|||
foreach (char ch in attFm) |
|||
{ |
|||
fm.Add(ch); |
|||
} |
|||
} |
|||
return fm; |
|||
} |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
using System; |
|||
|
|||
namespace FiveLetters.Model |
|||
{ |
|||
public class FiveLettersTask |
|||
{ |
|||
public DateTime Date { get; set; } |
|||
public string TaskGuid { get; set; } |
|||
public string Word { get; set; } |
|||
|
|||
public FiveLettersTask(DateTime date, string word) |
|||
{ |
|||
Date = date; |
|||
Word = word; |
|||
TaskGuid = Guid.NewGuid().ToString("N"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace FiveLetters.Model |
|||
{ |
|||
public interface IDictionaryProvider |
|||
{ |
|||
bool CheckWordForExistence(string effectiveWord); |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
namespace FiveLetters.Model |
|||
{ |
|||
public interface ITaskProvider |
|||
{ |
|||
FiveLettersTask GetTodayTask(); |
|||
FiveLettersTask GetTask(string taskGuid); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
using System; |
|||
|
|||
namespace FiveLetters.Model |
|||
{ |
|||
public class MockTaskProvider : ITaskProvider |
|||
{ |
|||
private FiveLettersTask _task; |
|||
|
|||
public MockTaskProvider(string word) |
|||
{ |
|||
_task = new FiveLettersTask(DateTime.Now, word); |
|||
|
|||
} |
|||
|
|||
public FiveLettersTask GetTask(string taskGuid) |
|||
{ |
|||
return _task; |
|||
} |
|||
|
|||
public FiveLettersTask GetTodayTask() |
|||
{ |
|||
return _task; |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
using Microsoft.AspNetCore.Hosting; |
|||
using Microsoft.Extensions.Configuration; |
|||
using Microsoft.Extensions.Hosting; |
|||
using Microsoft.Extensions.Logging; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace FiveLetters |
|||
{ |
|||
public class Program |
|||
{ |
|||
public static void Main(string[] args) |
|||
{ |
|||
CreateHostBuilder(args).Build().Run(); |
|||
} |
|||
|
|||
public static IHostBuilder CreateHostBuilder(string[] args) => |
|||
Host.CreateDefaultBuilder(args) |
|||
.ConfigureWebHostDefaults(webBuilder => |
|||
{ |
|||
webBuilder.UseStartup<Startup>(); |
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
{ |
|||
"$schema": "http://json.schemastore.org/launchsettings.json", |
|||
"iisSettings": { |
|||
"windowsAuthentication": false, |
|||
"anonymousAuthentication": true, |
|||
"iisExpress": { |
|||
"applicationUrl": "http://localhost:49928", |
|||
"sslPort": 0 |
|||
} |
|||
}, |
|||
"profiles": { |
|||
"IIS Express": { |
|||
"commandName": "IISExpress", |
|||
"launchBrowser": true, |
|||
"launchUrl": "swagger", |
|||
"environmentVariables": { |
|||
"ASPNETCORE_ENVIRONMENT": "Development" |
|||
} |
|||
}, |
|||
"FiveLetters": { |
|||
"commandName": "Project", |
|||
"dotnetRunMessages": "true", |
|||
"launchBrowser": true, |
|||
"launchUrl": "swagger", |
|||
"applicationUrl": "http://localhost:5000", |
|||
"environmentVariables": { |
|||
"ASPNETCORE_ENVIRONMENT": "Development" |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,56 @@ |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.AspNetCore.Hosting; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.Extensions.Configuration; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Hosting; |
|||
using Microsoft.Extensions.Logging; |
|||
using Microsoft.OpenApi.Models; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace FiveLetters |
|||
{ |
|||
public class Startup |
|||
{ |
|||
public Startup(IConfiguration configuration) |
|||
{ |
|||
Configuration = configuration; |
|||
} |
|||
|
|||
public IConfiguration Configuration { get; } |
|||
|
|||
// This method gets called by the runtime. Use this method to add services to the container.
|
|||
public void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
|
|||
services.AddControllers(); |
|||
services.AddSwaggerGen(c => |
|||
{ |
|||
c.SwaggerDoc("v1", new OpenApiInfo { Title = "FiveLetters", Version = "v1" }); |
|||
}); |
|||
} |
|||
|
|||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) |
|||
{ |
|||
if (env.IsDevelopment()) |
|||
{ |
|||
app.UseDeveloperExceptionPage(); |
|||
app.UseSwagger(); |
|||
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "FiveLetters v1")); |
|||
} |
|||
|
|||
app.UseRouting(); |
|||
|
|||
app.UseAuthorization(); |
|||
|
|||
app.UseEndpoints(endpoints => |
|||
{ |
|||
endpoints.MapControllers(); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
{ |
|||
"Logging": { |
|||
"LogLevel": { |
|||
"Default": "Information", |
|||
"Microsoft": "Warning", |
|||
"Microsoft.Hosting.Lifetime": "Information" |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
{ |
|||
"Logging": { |
|||
"LogLevel": { |
|||
"Default": "Information", |
|||
"Microsoft": "Warning", |
|||
"Microsoft.Hosting.Lifetime": "Information" |
|||
} |
|||
}, |
|||
"AllowedHosts": "*" |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
СЛОВО |
|||
БАСНЯ |
|||
АВЕРС |
|||
ТУМАН |
|||
БАРЖА |
|||
БИРЖА |
|||
АВЕРС |
|||
ТУМАН |
|||
БАРЖА |
|||
БИРЖА |
|||
АВЕРС |
|||
ТУМАН |
|||
БАРЖА |
|||
БИРЖА |
|||
АВЕРС |
|||
ТУМАН |
|||
БАРЖА |
|||
БИРЖА |
|||
АВЕРС |
|||
ТУМАН |
|||
БАРЖА |
|||
БИРЖА |
|||
АВЕРС |
|||
ТУМАН |
|||
БАРЖА |
|||
БИРЖА |
|||
АВЕРС |
|||
ТУМАН |
|||
БАРЖА |
|||
БИРЖА |
|||
ЗАМЕС |
|||
@ -0,0 +1,26 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>net5.0</TargetFramework> |
|||
|
|||
<IsPackable>false</IsPackable> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" /> |
|||
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" /> |
|||
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" /> |
|||
<PackageReference Include="coverlet.collector" Version="1.3.0" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\FiveLetters\FiveLetters.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<None Update="202503.txt"> |
|||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> |
|||
</None> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,96 @@ |
|||
using Microsoft.VisualStudio.TestTools.UnitTesting; |
|||
using FiveLetters.Model; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace FiveLetters.Model.Tests |
|||
{ |
|||
[TestClass()] |
|||
public class FiveLetterServerTests |
|||
{ |
|||
[TestMethod()] |
|||
public void shouldCreateOk() |
|||
{ |
|||
var st = new FiveLetterServer(new FileTaskProvider(), new FileDictionaryProvider(), 10); |
|||
Assert.AreNotEqual(st, null); |
|||
} |
|||
|
|||
[TestMethod()] |
|||
public void shouldTurnOk() |
|||
{ |
|||
string u1 = "9131212121"; |
|||
string u2 = "9131212122"; |
|||
// ----------- СЛОВО ---------------
|
|||
var st = new FiveLetterServer(new MockTaskProvider("СЛОВО"), new FileDictionaryProvider(), 6); |
|||
var r1 = st.GetResult(u1); |
|||
Assert.AreEqual(r1.User, u1); |
|||
var r2 = st.GetResult(u2); |
|||
Assert.AreEqual(r2.User, u2); |
|||
|
|||
// первый пользователь
|
|||
int iCount = 1; |
|||
FiveLettersResult r3 = st.Turn(u1, "ЙЦУКЕ"); |
|||
Assert.AreEqual(r3.Attempts.Count, iCount++); |
|||
Assert.AreEqual("", h_HsToString(r3.Attempts.Last().GetLettersFullMatch())); |
|||
Assert.AreEqual("", h_HsToString(r3.Attempts.Last().GetLettersPartialMatch())); |
|||
r3 = st.Turn(u1, "НГШЩЗ"); |
|||
Assert.AreEqual(r3.Attempts.Count, iCount++); |
|||
Assert.AreEqual("", h_HsToString(r3.Attempts.Last().GetLettersFullMatch())); |
|||
Assert.AreEqual("", h_HsToString(r3.Attempts.Last().GetLettersPartialMatch())); |
|||
Assert.AreEqual("", h_HsToString(r3.GetLettersFullMatch())); |
|||
Assert.AreEqual("", h_HsToString(r3.GetLettersPartialMatch())); |
|||
r3 = st.Turn(u1, "ХФЫВА"); |
|||
Assert.AreEqual(r3.Attempts.Count, iCount++); |
|||
Assert.AreEqual("В", h_HsToString(r3.Attempts.Last().GetLettersFullMatch())); |
|||
Assert.AreEqual("", h_HsToString(r3.Attempts.Last().GetLettersPartialMatch())); |
|||
Assert.AreEqual("В", h_HsToString(r3.GetLettersFullMatch())); |
|||
Assert.AreEqual("", h_HsToString(r3.GetLettersPartialMatch())); |
|||
r3 = st.Turn(u1, "ПРОЛД"); |
|||
Assert.AreEqual(r3.Attempts.Count, iCount++); |
|||
Assert.AreEqual("О", h_HsToString(r3.Attempts.Last().GetLettersFullMatch())); |
|||
Assert.AreEqual("Л", h_HsToString(r3.Attempts.Last().GetLettersPartialMatch())); |
|||
Assert.AreEqual("В,О", h_HsToString(r3.GetLettersFullMatch())); |
|||
Assert.AreEqual("Л", h_HsToString(r3.GetLettersPartialMatch())); |
|||
r3 = st.Turn(u1, "ЖЯЧСМ"); |
|||
Assert.AreEqual(r3.Attempts.Count, iCount++); |
|||
Assert.AreEqual("", h_HsToString(r3.Attempts.Last().GetLettersFullMatch())); |
|||
Assert.AreEqual("С", h_HsToString(r3.Attempts.Last().GetLettersPartialMatch())); |
|||
Assert.AreEqual("В,О", h_HsToString(r3.GetLettersFullMatch())); |
|||
Assert.AreEqual("Л,С", h_HsToString(r3.GetLettersPartialMatch())); |
|||
// второй пользователь
|
|||
var r4 = st.Turn(u2, "ИТЬЬБ"); |
|||
Assert.AreEqual(r4.Attempts.Count, 1); |
|||
Assert.AreEqual("", h_HsToString(r4.Attempts.Last().GetLettersFullMatch())); |
|||
Assert.AreEqual("", h_HsToString(r4.Attempts.Last().GetLettersPartialMatch())); |
|||
Assert.AreEqual("", h_HsToString(r4.GetLettersFullMatch())); |
|||
Assert.AreEqual("", h_HsToString(r4.GetLettersPartialMatch())); |
|||
|
|||
Assert.AreEqual(r3.Result, EResultGameType.InProcess); |
|||
r3 = st.Turn(u1, "ЮЪХХХ"); |
|||
Assert.AreEqual(r3.Attempts.Count, iCount++); |
|||
// TODO: check for status
|
|||
Assert.AreEqual(r3.Result, EResultGameType.Failed); |
|||
} |
|||
|
|||
[TestMethod()] |
|||
public void GetResultTest() |
|||
{ |
|||
string u1 = "9131212121"; |
|||
string u2 = "9131212122"; |
|||
var st = new FiveLetterServer(new MockTaskProvider("12345"), new FileDictionaryProvider(), 10); |
|||
var r1 = st.GetResult(u1); |
|||
Assert.AreEqual(r1.User, u1); |
|||
var r2 = st.GetResult(u2); |
|||
Assert.AreEqual(r2.User, u2); |
|||
} |
|||
|
|||
|
|||
private string h_HsToString(HashSet<char> hs) |
|||
{ |
|||
return String.Join(',', hs.OrderBy(p => p)); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue