-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #488 from DenisPimenov/compact-list-contains
Add Contains and IndexOf methods for consistency with System.Collections.Generic.List<>
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Collections.Generic; | ||
using JetBrains.Collections; | ||
using NUnit.Framework; | ||
|
||
namespace Test.Lifetimes.Collections | ||
{ | ||
[TestFixture] | ||
public class CompactListTest | ||
{ | ||
[TestCase(new int[0], 1, false)] | ||
[TestCase(new[] { 1 }, 1, true)] | ||
[TestCase(new[] { 1 }, 2, false)] | ||
[TestCase(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 5, true)] | ||
[TestCase(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 0, false)] | ||
public void TestContains(int[] values, int value, bool expected) | ||
{ | ||
var compactList = new CompactList<int>(); | ||
for (int i = 0; i < values.Length; i++) | ||
{ | ||
compactList.Add(values[i]); | ||
} | ||
|
||
Assert.AreEqual(compactList.Contains(value, EqualityComparer<int>.Default), expected); | ||
} | ||
|
||
[TestCase(new int[0], 1, -1)] | ||
[TestCase(new[] { 1 }, 1, 0)] | ||
[TestCase(new[] { 1 }, 2, -1)] | ||
[TestCase(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 5, 4)] | ||
[TestCase(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 0, -1)] | ||
public void TestIndexOf(int[] values, int value, int expectedIndex) | ||
{ | ||
var compactList = new CompactList<int>(); | ||
for (int i = 0; i < values.Length; i++) | ||
{ | ||
compactList.Add(values[i]); | ||
} | ||
|
||
Assert.AreEqual(compactList.IndexOf(value, EqualityComparer<int>.Default), expectedIndex); | ||
} | ||
} | ||
} |