Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,39 @@
namespace AdventureTime
using System;

namespace AdventureTime
{
internal class Program
{
private static void Main()
{
DateTime dt = Time.WhatTimeIsIt();
DateTime udt = Time.WhatTimeIsItInUtc();

Console.WriteLine(dt);
Console.WriteLine(udt);

// all the same
Console.WriteLine(Time.SpecifyKind(dt, DateTimeKind.Utc));
Console.WriteLine(Time.SpecifyKind(dt, DateTimeKind.Local));
Console.WriteLine(Time.SpecifyKind(dt, DateTimeKind.Unspecified));

var roundtrip = Time.ToRoundTripFormatString(dt);
Console.WriteLine(roundtrip);
Console.WriteLine(Time.ParseFromRoundTripFormat(roundtrip));

Console.WriteLine(Time.AddTenSeconds(dt));
Console.WriteLine(Time.AddTenSecondsV2(dt));

Console.WriteLine(Time.GetHoursBetween(udt, dt));
Console.WriteLine(Time.GetTotalMinutesInThreeMonths());

Console.WriteLine(Time.GetAdventureTimeDurationInMinutes_ver0_Dumb());
Console.WriteLine(Time.GetGenderSwappedAdventureTimeDurationInMinutes_ver0_Dumb());
Console.WriteLine(Time.GetAdventureTimeDurationInMinutes_ver1_FeelsSmarter());
Console.WriteLine(Time.GetAdventureTimeDurationInMinutes_ver3_NodaTime());

Console.WriteLine(Time.AreEqualBirthdays(dt, udt));
Console.WriteLine(Time.AreEqualBirthdays(dt, udt.AddDays(1)));
}
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<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" />
<PackageReference Include="xUnit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BoringVector\BoringVector.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using Xunit;

namespace BoringVector.Tests
{
public class VectorTest
{
[Fact]
public void Test_SquareLength()
{
Vector v = new Vector(3, 4);
Assert.Equal(25, v.SquareLength());
}
[Theory]
[InlineData(1, 5)]
[InlineData(0, 0)]
[InlineData(-1, 1)]
public void Test_Add(double x, double y)
{
Vector v = new Vector(3, 4);
Vector u = new Vector(x, y);
v.Add(u);
Assert.Equal(new Vector(3+x, 4+y).ToString(), v.ToString());
}
[Theory]
[InlineData(5)]
[InlineData(0)]
[InlineData(-2)]
public void Test_Scale(double scale)
{
Vector v = new Vector(3, 4);
v.Scale(scale);
Assert.Equal(new Vector(3*scale, 4*scale).ToString(), v.ToString());
}
[Fact]
public void Test_DotProduct()
{
Vector v = new Vector(3, 4);
Vector u = new Vector(1, -1);
Assert.Equal(-1, v.DotProduct(u));
}
[Fact]
public void Test_CrossProduct()
{
Vector v = new Vector(3, 4);
Vector u = new Vector(4, -3);
Assert.Equal(-25, v.CrossProduct(u));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp5.0</TargetFramework>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("BoringVector.Tests")]

namespace BoringVector
{
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,10 +1,58 @@
namespace BoringVector
using System;

namespace BoringVector
{
enum VectorRelation
{
General,
Parallel,
Orthogonal
}
/*
Здесь тебе нужно написать класс с методами-расширениями структуры Vector:
- IsZero: проверяет, является ли вектор нулевым, т.е. его координаты близки к нулю (в эпсилон окрестности). За эпсилон здесь и далее берем 1e-6.
- IsZero: проверяет, является ли вектор нулевым, т.е. его координаты
близки к нулю (в эпсилон окрестности). За эпсилон здесь и далее
берем 1e-6.
- Normalize: нормализует вектор
- GetAngleBetween: возвращает угол между двумя векторами в радианах. Примечание: нулевой вектор сонаправлен любому другому.
- GetRelation: возвращает значение перечесления VectorRelation(General, Parallel, Orthogonal) - отношение между двумя векторами("общий случай", параллельны, перпендикулярны). Перечисление задавать тоже тебе)
- GetAngleBetween: возвращает угол между двумя векторами в радианах.
Примечание: нулевой вектор сонаправлен любому другому.
- GetRelation: возвращает значение перечесления
VectorRelation(General, Parallel, Orthogonal) - отношение между
двумя векторами("общий случай", параллельны, перпендикулярны).
Перечисление задавать тоже тебе)
*/
internal class ExtendedVector : Vector
{
const double eps = 0.000001;
public ExtendedVector(double x, double y) : base(x, y) {}
public bool IsZero()
{
return Math.Abs(x) < eps && Math.Abs(y) < eps;
}

public ExtendedVector Normalize()
{
double len = Math.Sqrt(SquareLength());
x /= len;
y /= len;
return this;
}

static public double GetAngleBetween(ExtendedVector v, ExtendedVector u)
{
if (v.IsZero() || u.IsZero()) {
return 0;
}
return Math.Acos(v.Normalize().DotProduct(u.Normalize()));
}
static public VectorRelation GetRelation(ExtendedVector v, ExtendedVector u)
{
if (v.CrossProduct(u) == 0) {
return VectorRelation.Parallel;
} else if (v.DotProduct(u) == 0) {
return VectorRelation.Orthogonal;
}
return VectorRelation.General;
}
}
}