Skip to content

Commit dfab985

Browse files
TimeSlots
1 parent 56a866a commit dfab985

File tree

7 files changed

+254
-0
lines changed

7 files changed

+254
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProjectGuid>{5C052681-DA3C-4FEA-8E02-7DFBB2A18B22}</ProjectGuid>
7+
<OutputType>Library</OutputType>
8+
<AppDesignerFolder>Properties</AppDesignerFolder>
9+
<RootNamespace>Microsoft.Azure.Commands.Common.Strategies.UnitTest</RootNamespace>
10+
<AssemblyName>Microsoft.Azure.Commands.Common.Strategies.UnitTest</AssemblyName>
11+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
15+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
16+
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
17+
<IsCodedUITest>False</IsCodedUITest>
18+
<TestProjectType>UnitTest</TestProjectType>
19+
</PropertyGroup>
20+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
21+
<DebugSymbols>true</DebugSymbols>
22+
<DebugType>full</DebugType>
23+
<Optimize>false</Optimize>
24+
<OutputPath>bin\Debug\</OutputPath>
25+
<DefineConstants>DEBUG;TRACE</DefineConstants>
26+
<ErrorReport>prompt</ErrorReport>
27+
<WarningLevel>4</WarningLevel>
28+
</PropertyGroup>
29+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>true</Optimize>
32+
<OutputPath>bin\Release\</OutputPath>
33+
<DefineConstants>TRACE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
</PropertyGroup>
37+
<ItemGroup>
38+
<Reference Include="System" />
39+
</ItemGroup>
40+
<Choose>
41+
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
42+
<ItemGroup>
43+
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
44+
</ItemGroup>
45+
</When>
46+
<Otherwise>
47+
<ItemGroup>
48+
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
49+
</ItemGroup>
50+
</Otherwise>
51+
</Choose>
52+
<ItemGroup>
53+
<Compile Include="TimeSlotTest.cs" />
54+
<Compile Include="Properties\AssemblyInfo.cs" />
55+
</ItemGroup>
56+
<ItemGroup>
57+
<ProjectReference Include="..\Commands.Common.Strategies\Commands.Common.Strategies.csproj">
58+
<Project>{eea69772-d41b-482a-9252-2b4595c59e53}</Project>
59+
<Name>Commands.Common.Strategies</Name>
60+
</ProjectReference>
61+
</ItemGroup>
62+
<Choose>
63+
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
64+
<ItemGroup>
65+
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
66+
<Private>False</Private>
67+
</Reference>
68+
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
69+
<Private>False</Private>
70+
</Reference>
71+
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
72+
<Private>False</Private>
73+
</Reference>
74+
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
75+
<Private>False</Private>
76+
</Reference>
77+
</ItemGroup>
78+
</When>
79+
</Choose>
80+
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
81+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
82+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
83+
Other similar extension points exist, see Microsoft.Common.targets.
84+
<Target Name="BeforeBuild">
85+
</Target>
86+
<Target Name="AfterBuild">
87+
</Target>
88+
-->
89+
</Project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Commands.Common.Strategies.UnitTest")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Commands.Common.Strategies.UnitTest")]
13+
[assembly: AssemblyCopyright("Copyright © 2017")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("5c052681-da3c-4fea-8e02-7dfbb2a18b22")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
3+
namespace Microsoft.Azure.Commands.Common.Strategies.UnitTest
4+
{
5+
[TestClass]
6+
public class TimeSlotTest
7+
{
8+
[TestMethod]
9+
public void AddTest()
10+
{
11+
var first = new TimeSlot();
12+
13+
Assert.AreEqual(0, first.Duration);
14+
Assert.AreEqual(0, first.TaskCount);
15+
Assert.AreEqual(null, first.Next);
16+
17+
var next = first.AddTask(50);
18+
19+
Assert.AreEqual(50, first.Duration);
20+
Assert.AreEqual(1, first.TaskCount);
21+
Assert.AreEqual(next, first.Next);
22+
23+
Assert.AreEqual(0, next.Duration);
24+
Assert.AreEqual(0, next.TaskCount);
25+
Assert.AreEqual(null, next.Next);
26+
27+
var next2 = first.AddTask(50);
28+
29+
Assert.AreEqual(50, first.Duration);
30+
Assert.AreEqual(2, first.TaskCount);
31+
Assert.AreEqual(next2, first.Next);
32+
Assert.AreEqual(next, first.Next);
33+
34+
Assert.AreEqual(0, next2.Duration);
35+
Assert.AreEqual(0, next2.TaskCount);
36+
Assert.AreEqual(null, next2.Next);
37+
38+
var next3 = first.AddTask(30);
39+
Assert.AreEqual(30, first.Duration);
40+
Assert.AreEqual(3, first.TaskCount);
41+
Assert.AreEqual(next3, first.Next);
42+
43+
Assert.AreEqual(20, next3.Duration);
44+
Assert.AreEqual(2, next3.TaskCount);
45+
Assert.AreEqual(next2, next3.Next);
46+
Assert.AreEqual(next, next3.Next);
47+
48+
Assert.AreEqual(0, next2.Duration);
49+
Assert.AreEqual(0, next2.TaskCount);
50+
Assert.AreEqual(null, next2.Next);
51+
52+
var next4 = first.AddTask(75);
53+
Assert.AreEqual(25, next2.Duration);
54+
Assert.AreEqual(1, next2.TaskCount);
55+
Assert.AreEqual(next4, next2.Next);
56+
57+
Assert.AreEqual(0, next4.Duration);
58+
Assert.AreEqual(0, next4.TaskCount);
59+
Assert.AreEqual(null, next4.Next);
60+
}
61+
}
62+
}

src/ResourceManager/Common/Commands.Common.Strategies/Commands.Common.Strategies.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@
7373
<Compile Include="IResourceConfig.cs" />
7474
<Compile Include="IResourceConfigVisitor.cs" />
7575
<Compile Include="IShouldProcess.cs" />
76+
<Compile Include="TimeSlot.cs" />
7677
<Compile Include="StateOperationContext.cs" />
7778
<Compile Include="Compute\ComputeStrategy.cs" />
7879
<Compile Include="Compute\VirtualMachineStrategy.cs" />
7980
<Compile Include="SyncTaskScheduler.cs" />
81+
<Compile Include="TimeSlotExtensions.cs" />
8082
<Compile Include="UpdateStateExtensions.cs" />
8183
<Compile Include="CreateOrUpdateAsyncParams.cs" />
8284
<Compile Include="EntityConfigExtensions.cs" />
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
namespace Microsoft.Azure.Commands.Common.Strategies
2+
{
3+
public sealed class TimeSlot
4+
{
5+
public int Duration { get; private set; }
6+
7+
public int TaskCount { get; private set; }
8+
9+
public TimeSlot Next { get; private set; }
10+
11+
public bool IsLast => Next == null;
12+
13+
public TimeSlot() : this(0, 0, null)
14+
{
15+
}
16+
17+
TimeSlot(int duration, int taskCount, TimeSlot next)
18+
{
19+
Duration = duration;
20+
TaskCount = taskCount;
21+
Next = next;
22+
}
23+
24+
public TimeSlot AddTask(int duration)
25+
{
26+
if (duration <= 0)
27+
{
28+
return this;
29+
}
30+
else if (Next == null)
31+
{
32+
Next = new TimeSlot();
33+
Duration = duration;
34+
TaskCount = 1;
35+
return Next;
36+
}
37+
else if (duration < Duration)
38+
{
39+
Next = new TimeSlot(Duration - duration, TaskCount, Next);
40+
Duration = duration;
41+
TaskCount++;
42+
return Next;
43+
}
44+
else // if (Duration <= duration)
45+
{
46+
TaskCount++;
47+
return Next.AddTask(duration - Duration);
48+
}
49+
}
50+
}
51+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Microsoft.Azure.Commands.Common.Strategies
2+
{
3+
class TimeSlotExtensions
4+
{
5+
public TimeSlot
6+
}
7+
}

src/ResourceManager/Compute/Compute.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.Common.Authenticat
4040
EndProject
4141
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.Common.Strategies", "..\Common\Commands.Common.Strategies\Commands.Common.Strategies.csproj", "{EEA69772-D41B-482A-9252-2B4595C59E53}"
4242
EndProject
43+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.Common.Strategies.UnitTest", "..\Common\Commands.Common.Strategies.UnitTest\Commands.Common.Strategies.UnitTest.csproj", "{5C052681-DA3C-4FEA-8E02-7DFBB2A18B22}"
44+
EndProject
4345
Global
4446
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4547
Debug|Any CPU = Debug|Any CPU
@@ -118,13 +120,18 @@ Global
118120
{EEA69772-D41B-482A-9252-2B4595C59E53}.Debug|Any CPU.Build.0 = Debug|Any CPU
119121
{EEA69772-D41B-482A-9252-2B4595C59E53}.Release|Any CPU.ActiveCfg = Release|Any CPU
120122
{EEA69772-D41B-482A-9252-2B4595C59E53}.Release|Any CPU.Build.0 = Release|Any CPU
123+
{5C052681-DA3C-4FEA-8E02-7DFBB2A18B22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
124+
{5C052681-DA3C-4FEA-8E02-7DFBB2A18B22}.Debug|Any CPU.Build.0 = Debug|Any CPU
125+
{5C052681-DA3C-4FEA-8E02-7DFBB2A18B22}.Release|Any CPU.ActiveCfg = Release|Any CPU
126+
{5C052681-DA3C-4FEA-8E02-7DFBB2A18B22}.Release|Any CPU.Build.0 = Release|Any CPU
121127
EndGlobalSection
122128
GlobalSection(SolutionProperties) = preSolution
123129
HideSolutionNode = FALSE
124130
EndGlobalSection
125131
GlobalSection(NestedProjects) = preSolution
126132
{37C44181-3F1B-4ABD-8089-26DFAB4B6BA8} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}
127133
{3436A126-EDC9-4060-8952-9A1BE34CDD95} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}
134+
{5C052681-DA3C-4FEA-8E02-7DFBB2A18B22} = {95C16AED-FD57-42A0-86C3-2CF4300A4817}
128135
EndGlobalSection
129136
GlobalSection(ExtensibilityGlobals) = postSolution
130137
SolutionGuid = {54E53EE0-76A1-4911-8FED-63555F09459F}

0 commit comments

Comments
 (0)