Skip to content

Commit 05ee729

Browse files
author
SC
committed
feat: adds tests to meeting rooms
1 parent 06d83fb commit 05ee729

File tree

5 files changed

+111
-15
lines changed

5 files changed

+111
-15
lines changed
Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections;
3-
using System.Collections.Generic;
4-
5-
namespace lintcode
1+
namespace _16_Intervals.L252_MeetingRoom
62
{
73

84
// Definition of Interval:
@@ -16,7 +12,7 @@ public Interval(int start, int end)
1612
}
1713
}
1814

19-
class Solution
15+
public class Solution
2016
{
2117
/**
2218
* @param intervals: an array of meeting time intervals
@@ -25,7 +21,7 @@ class Solution
2521
public bool CanAttendMeetings(List<Interval> intervals)
2622
{
2723
// Write your code here
28-
intervals.Sort(SortByStartTimeHeleper.CompareStartTime);
24+
intervals.Sort(SortByStartTimeHelper.CompareStartTime);
2925

3026
for (int i = 1; i < intervals.Count; i++)
3127
{
@@ -35,18 +31,15 @@ public bool CanAttendMeetings(List<Interval> intervals)
3531
if (i1.end > i2.start)
3632
return false;
3733
}
38-
return false;
34+
return true;
3935
}
4036

4137
}
4238

43-
public class SortByStartTimeHeleper
39+
public class SortByStartTimeHelper
4440
{
45-
public static int CompareStartTime(object? x, object? y)
41+
public static int CompareStartTime(Interval a, Interval b)
4642
{
47-
Interval a = (Interval)x;
48-
Interval b = (Interval)y;
49-
5043
if (a.start > b.start)
5144
return 1;
5245
if (a.start < b.start)
@@ -57,6 +50,39 @@ public static int CompareStartTime(object? x, object? y)
5750

5851
}
5952

60-
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+
71+
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+
82+
83+
84+
85+
86+
6187

6288
}

csharp/16-Intervals/main/L252-MeetingRoom/readme.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@ Output: true
2121

2222
Explanation:
2323

24-
Two times will not conflict
24+
Two times will not conflict
25+
26+
## Constraints
27+
- 0 <= intervals.length <= 500
28+
- 0 <= intervals[i].start < intervals[i].end <= 1,000,000
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<RootNamespace>_16_Intervals_Tests</RootNamespace>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="FluentAssertions" Version="6.6.0" />
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
13+
<PackageReference Include="NUnit" Version="4.3.2" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\16-Intervals\main\16_Intervals.csproj" />
18+
</ItemGroup>
19+
20+
</Project>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using _16_Intervals.L252_MeetingRoom;
2+
using FluentAssertions;
3+
using NUnit.Framework;
4+
5+
namespace _16_Intervals_Tests;
6+
7+
public class L252_IntervalsTests
8+
{
9+
[Test]
10+
public void Example1_Test()
11+
{
12+
var intervals = new List<Interval>()
13+
{
14+
new(0, 30),
15+
new(5, 10),
16+
new(15, 20)
17+
};
18+
19+
var solution = new Solution();
20+
var result = solution.CanAttendMeetings(intervals);
21+
22+
result.Should().Be(false);
23+
}
24+
25+
[Test]
26+
public void Example2_Test()
27+
{
28+
var intervals = new List<Interval>()
29+
{
30+
new(5, 8),
31+
new(9, 15)
32+
33+
};
34+
var solution = new Solution();
35+
var result = solution.CanAttendMeetings(intervals);
36+
37+
result.Should().Be(true);
38+
}
39+
40+
}

csharp/Neetcode.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "18_BitManipulation", "18_Bi
5353
EndProject
5454
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "18_BitManipulation_Tests", "18_BitManipulation_Tests\18_BitManipulation_Tests.csproj", "{E65DC80C-5671-46BA-95A6-77B8FB7456AD}"
5555
EndProject
56+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "16_Intervals_Tests", "16_Intervals_Tests\16_Intervals_Tests.csproj", "{58105687-8782-463B-BD1C-94E4AAC78261}"
57+
EndProject
5658
Global
5759
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5860
Debug|Any CPU = Debug|Any CPU
@@ -163,6 +165,10 @@ Global
163165
{E65DC80C-5671-46BA-95A6-77B8FB7456AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
164166
{E65DC80C-5671-46BA-95A6-77B8FB7456AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
165167
{E65DC80C-5671-46BA-95A6-77B8FB7456AD}.Release|Any CPU.Build.0 = Release|Any CPU
168+
{58105687-8782-463B-BD1C-94E4AAC78261}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
169+
{58105687-8782-463B-BD1C-94E4AAC78261}.Debug|Any CPU.Build.0 = Debug|Any CPU
170+
{58105687-8782-463B-BD1C-94E4AAC78261}.Release|Any CPU.ActiveCfg = Release|Any CPU
171+
{58105687-8782-463B-BD1C-94E4AAC78261}.Release|Any CPU.Build.0 = Release|Any CPU
166172
EndGlobalSection
167173
GlobalSection(SolutionProperties) = preSolution
168174
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)