Skip to content

Conversation

@bygu4
Copy link
Owner

@bygu4 bygu4 commented Oct 31, 2024

No description provided.

Comment on lines +13 to +19
public static IEnumerable<TestCaseData> TestCases()
{
foreach (var testFile in Directory.GetFileSystemEntries(TestFilesPath))
{
yield return new TestCaseData(testFile);
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static IEnumerable<TestCaseData> TestCases()
{
foreach (var testFile in Directory.GetFileSystemEntries(TestFilesPath))
{
yield return new TestCaseData(testFile);
}
}
public static IEnumerable<TestCaseData> TestCases()
=> Directory.GetFileSystemEntries(TestFilesPath).Select(e => new TestCaseData(e));

Если проходите по коллекции, чтобы сделать yield, это сразу знак, что делаете что-то не так, коллекция ведь и так коллекция, а yield нужен, чтобы по набору значений коллекцию сделать

using System.Security.Cryptography;
using System.Text;

namespace CheckSum;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

namespace лучше перед using


private static byte[] GetFileCheckSumSequentially(string path)
{
var content = File.ReadAllBytes(path);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если файл в память не лезет, быть беде

result.AddRange(GetCheckSumSequentially(entry));
}

return result.ToArray();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Так это не чексумма, а конкатенированный набор чексумм. Надо было это ещё в MD5 запихать.

{
var content = await File.ReadAllBytesAsync(path);
return MD5.HashData(content);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вы не поверите, но и в однопоточном случае стоило так с файлом и поступать. Синхронный ввод-вывод в современном мире, я бы сказал, вообще не нужен. Тут оно асинхронное, но не параллельное, так что не противоречит условию.

var tasks = new List<Task<byte[]>>();
var name = Path.GetFileName(path);
var nameHash = MD5.HashData(Encoding.Unicode.GetBytes(name));
tasks.Add(Task.Run(() => nameHash));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Он же уже посчитан. Task.Result?

{
result[currentIndex] = task.Result[i];
++currentIndex;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Процесс можно было немного автоматизировать через Array.Copy

}
}

return result;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И тоже, ожидался 128-битный хеш, вернули что попало

Comment on lines +15 to +22
public static class Program
{
/// <summary>
/// Main entry point of the program.
/// </summary>
/// <param name="args">First argument is the path of
/// the file to evaluate the check sum of.</param>
public static void Main(string[] args)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это не нужно, используйте top-level statements

stopWatch.Restart();
CheckSumUtils.GetCheckSumSequentially(path);
stopWatch.Stop();
Console.WriteLine($"Time of the sequential evaluation: {stopWatch.Elapsed}");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Указывайте единицы измерения всегда

@bygu4 bygu4 changed the base branch from main to tests April 12, 2025 18:51
@bygu4 bygu4 merged commit 836e178 into tests Apr 12, 2025
4 checks passed
@bygu4 bygu4 deleted the test1 branch April 12, 2025 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants