Skip to content

Commit

Permalink
Move tests to another csproj.
Browse files Browse the repository at this point in the history
Add nunit as nugget dependency.
Add a new test to check for possible bug in Back() implementation
Fix some typos in the main class documentation.
  • Loading branch information
joaoportela committed May 15, 2018
1 parent 23c1cf0 commit 6a6a79c
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 49 deletions.
68 changes: 68 additions & 0 deletions CircularBuffer.Tests/CircularBuffer.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\NUnit.3.10.1\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.10.1\build\NUnit.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{0E77FF57-F87E-4481-B3B4-97ADDD44C244}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CircularBuffer.Tests</RootNamespace>
<AssemblyName>CircularBuffer.Tests</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework, Version=3.10.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.10.1\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CircularBufferTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CircularBuffer\CircularBuffer.csproj">
<Project>{fccf42ae-1500-4ae0-9a5c-40347b86d921}</Project>
<Name>CircularBuffer</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\NUnit.3.10.1\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.10.1\build\NUnit.props'))" />
</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using NUnit.Framework;
using System;
using System.Collections;
using System.Linq;

namespace CircularBuffer
namespace CircularBuffer.Tests
{
[TestFixture()]
[TestFixture]
public class CircularBufferTests
{
[Test()]
public void CircularBuffer_ConstructurSizeIndexAccess_CorrectContent()
[Test]
public void CircularBuffer_ConstructorSizeIndexAccess_CorrectContent()
{
var buffer = new CircularBuffer<int>(5, new[] { 0, 1, 2, 3 });

Expand All @@ -20,15 +20,15 @@ public void CircularBuffer_ConstructurSizeIndexAccess_CorrectContent()
}
}

[Test()]
[Test]
public void CircularBuffer_Constructor_ExceptionWhenSourceIsLargerThanCapacity()
{
Assert.That(() => new CircularBuffer<int>(3, new[] { 0, 1, 2, 3 }),
Throws.Exception.TypeOf<ArgumentException>());
}

[Test()]
public void CircularBuffer_GetEnumeratorConstructorDefinedArray_Correctcontent()
[Test]
public void CircularBuffer_GetEnumeratorConstructorDefinedArray_CorrectContent()
{
var buffer = new CircularBuffer<int>(5, new[] { 0, 1, 2, 3 });

Expand All @@ -40,7 +40,7 @@ public void CircularBuffer_GetEnumeratorConstructorDefinedArray_Correctcontent()
}
}

[Test()]
[Test]
public void CircularBuffer_PushBack_CorrectContent()
{
var buffer = new CircularBuffer<int>(5);
Expand All @@ -57,7 +57,7 @@ public void CircularBuffer_PushBack_CorrectContent()
}
}

[Test()]
[Test]
public void CircularBuffer_PushBackOverflowingBuffer_CorrectContent()
{
var buffer = new CircularBuffer<int>(5);
Expand All @@ -70,8 +70,8 @@ public void CircularBuffer_PushBackOverflowingBuffer_CorrectContent()
Assert.That(buffer.ToArray(), Is.EqualTo(new[] { 5, 6, 7, 8, 9 }));
}

[Test()]
public void CircularBuffer_GetEnumeratorOverflowedArray_Correctcontent()
[Test]
public void CircularBuffer_GetEnumeratorOverflowedArray_CorrectContent()
{
var buffer = new CircularBuffer<int>(5);

Expand All @@ -89,16 +89,16 @@ public void CircularBuffer_GetEnumeratorOverflowedArray_Correctcontent()
}
}

[Test()]
public void CircularBuffer_ToArrayConstructorDefinedArray_Correctcontent()
[Test]
public void CircularBuffer_ToArrayConstructorDefinedArray_CorrectContent()
{
var buffer = new CircularBuffer<int>(5, new[] { 0, 1, 2, 3 });

Assert.That(buffer.ToArray(), Is.EqualTo(new[] { 0, 1, 2, 3 }));
}

[Test()]
public void CircularBuffer_ToArrayOverflowedBuffer_Correctcontent()
[Test]
public void CircularBuffer_ToArrayOverflowedBuffer_CorrectContent()
{
var buffer = new CircularBuffer<int>(5);

Expand All @@ -110,7 +110,7 @@ public void CircularBuffer_ToArrayOverflowedBuffer_Correctcontent()
Assert.That(buffer.ToArray(), Is.EqualTo(new[] { 5, 6, 7, 8, 9 }));
}

[Test()]
[Test]
public void CircularBuffer_PushFront_CorrectContent()
{
var buffer = new CircularBuffer<int>(5);
Expand All @@ -123,7 +123,7 @@ public void CircularBuffer_PushFront_CorrectContent()
Assert.That(buffer.ToArray(), Is.EqualTo(new[] { 4, 3, 2, 1, 0 }));
}

[Test()]
[Test]
public void CircularBuffer_PushFrontAndOverflow_CorrectContent()
{
var buffer = new CircularBuffer<int>(5);
Expand All @@ -136,22 +136,22 @@ public void CircularBuffer_PushFrontAndOverflow_CorrectContent()
Assert.That(buffer.ToArray(), Is.EqualTo(new[] { 9, 8, 7, 6, 5 }));
}

[Test()]
[Test]
public void CircularBuffer_Front_CorrectItem()
{
var buffer = new CircularBuffer<int>(5, new[] { 0, 1, 2, 3, 4 });

Assert.That(buffer.Front(), Is.EqualTo(0));
}

[Test()]
[Test]
public void CircularBuffer_Back_CorrectItem()
{
var buffer = new CircularBuffer<int>(5, new[] { 0, 1, 2, 3, 4 });
Assert.That(buffer.Back(), Is.EqualTo(4));
}

[Test()]
[Test]
public void CircularBuffer_BackOfBufferOverflowByOne_CorrectItem()
{
var buffer = new CircularBuffer<int>(5, new[] { 0, 1, 2, 3, 4 });
Expand All @@ -160,26 +160,26 @@ public void CircularBuffer_BackOfBufferOverflowByOne_CorrectItem()
Assert.That(buffer.Back(), Is.EqualTo(42));
}

[Test()]
[Test]
public void CircularBuffer_Front_EmptyBufferThrowsException()
{
var buffer = new CircularBuffer<int>(5);

Assert.That(() => buffer.Front(),
Throws.Exception.TypeOf<InvalidOperationException>().
With.Property("Message").ContainsSubstring("empty buffer"));
With.Property("Message").Contains("empty buffer"));
}

[Test()]
[Test]
public void CircularBuffer_Back_EmptyBufferThrowsException()
{
var buffer = new CircularBuffer<int>(5);
Assert.That(() => buffer.Back(),
Throws.Exception.TypeOf<InvalidOperationException>().
With.Property("Message").ContainsSubstring("empty buffer"));
With.Property("Message").Contains("empty buffer"));
}

[Test()]
[Test]
public void CircularBuffer_PopBack_RemovesBackElement()
{
var buffer = new CircularBuffer<int>(5, new[] { 0, 1, 2, 3, 4 });
Expand All @@ -192,7 +192,7 @@ public void CircularBuffer_PopBack_RemovesBackElement()
Assert.That(buffer.ToArray(), Is.EqualTo(new[] { 0, 1, 2, 3 }));
}

[Test()]
[Test]
public void CircularBuffer_PopBackInOverflowBuffer_RemovesBackElement()
{
var buffer = new CircularBuffer<int>(5, new[] { 0, 1, 2, 3, 4 });
Expand All @@ -207,7 +207,7 @@ public void CircularBuffer_PopBackInOverflowBuffer_RemovesBackElement()
Assert.That(buffer.ToArray(), Is.EqualTo(new[] { 1, 2, 3, 4 }));
}

[Test()]
[Test]
public void CircularBuffer_PopFront_RemovesBackElement()
{
var buffer = new CircularBuffer<int>(5, new[] { 0, 1, 2, 3, 4 });
Expand All @@ -220,7 +220,7 @@ public void CircularBuffer_PopFront_RemovesBackElement()
Assert.That(buffer.ToArray(), Is.EqualTo(new[] { 1, 2, 3, 4 }));
}

[Test()]
[Test]
public void CircularBuffer_PopFrontInOverflowBuffer_RemovesBackElement()
{
var buffer = new CircularBuffer<int>(5, new[] { 0, 1, 2, 3, 4 });
Expand All @@ -235,7 +235,7 @@ public void CircularBuffer_PopFrontInOverflowBuffer_RemovesBackElement()
Assert.That(buffer.ToArray(), Is.EqualTo(new[] { 0, 1, 2, 3 }));
}

[Test()]
[Test]
public void CircularBuffer_SetIndex_ReplacesElement()
{
var buffer = new CircularBuffer<int>(5, new[] { 0, 1, 2, 3, 4 });
Expand All @@ -245,5 +245,22 @@ public void CircularBuffer_SetIndex_ReplacesElement()

Assert.That(buffer.ToArray(), Is.EqualTo(new[] { 0, 10, 2, 30, 4 }));
}

[Test]
public void CircularBuffer_Back_BugFix()
{
// test to confirm this issue does not happen:
// https://github.com/joaoportela/CircullarBuffer-CSharp/issues/2

var buffer = new CircularBuffer<int>(8, Enumerable.Range(0, 8).ToArray());

for (int i = 0; i < 4; i++)
{
buffer.PopFront();
}
buffer.PushBack(8);

Assert.That(buffer.Back(), Is.EqualTo(8));
}
}
}
36 changes: 36 additions & 0 deletions CircularBuffer.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CircularBuffer.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CircularBuffer.Tests")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("0e77ff57-f87e-4481-b3b4-97addd44c244")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
4 changes: 4 additions & 0 deletions CircularBuffer.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="3.10.1" targetFramework="net461" />
</packages>
26 changes: 20 additions & 6 deletions CircularBuffer.sln
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2000
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CircularBuffer", "CircularBuffer\CircularBuffer.csproj", "{FCCF42AE-1500-4AE0-9A5C-40347B86D921}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CircularBufferExample", "CircularBufferExample\CircularBufferExample.csproj", "{57E99177-94F0-4715-A91B-6FAE3F6BC37D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CircularBuffer.Tests", "CircularBuffer.Tests\CircularBuffer.Tests.csproj", "{0E77FF57-F87E-4481-B3B4-97ADDD44C244}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{57E99177-94F0-4715-A91B-6FAE3F6BC37D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{57E99177-94F0-4715-A91B-6FAE3F6BC37D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{57E99177-94F0-4715-A91B-6FAE3F6BC37D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{57E99177-94F0-4715-A91B-6FAE3F6BC37D}.Release|Any CPU.Build.0 = Release|Any CPU
{FCCF42AE-1500-4AE0-9A5C-40347B86D921}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FCCF42AE-1500-4AE0-9A5C-40347B86D921}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FCCF42AE-1500-4AE0-9A5C-40347B86D921}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FCCF42AE-1500-4AE0-9A5C-40347B86D921}.Release|Any CPU.Build.0 = Release|Any CPU
{57E99177-94F0-4715-A91B-6FAE3F6BC37D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{57E99177-94F0-4715-A91B-6FAE3F6BC37D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{57E99177-94F0-4715-A91B-6FAE3F6BC37D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{57E99177-94F0-4715-A91B-6FAE3F6BC37D}.Release|Any CPU.Build.0 = Release|Any CPU
{0E77FF57-F87E-4481-B3B4-97ADDD44C244}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0E77FF57-F87E-4481-B3B4-97ADDD44C244}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E77FF57-F87E-4481-B3B4-97ADDD44C244}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0E77FF57-F87E-4481-B3B4-97ADDD44C244}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {11E77CCD-AC5E-4661-A929-7106FE4B70D4}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = CircularBuffer\CircularBuffer.csproj
Expand Down
Loading

0 comments on commit 6a6a79c

Please sign in to comment.