Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add basic Tuple<T1, T2> type
- Loading branch information
Showing
14 changed files
with
135 additions
and
4 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
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,56 @@ | ||
using LibGit2Sharp.Core.Compat; | ||
using LibGit2Sharp.Tests.TestHelpers; | ||
using NUnit.Framework; | ||
|
||
namespace LibGit2Sharp.Tests | ||
{ | ||
[TestFixture] | ||
public class TupleFixture | ||
{ | ||
const int integer = 2; | ||
const string stringy = "hello"; | ||
|
||
private readonly Tuple<int, string> sut = new Tuple<int, string>(integer, stringy); | ||
|
||
[Test] | ||
public void Properties() | ||
{ | ||
sut.Item1.ShouldEqual(integer); | ||
sut.Item2.ShouldEqual(stringy); | ||
} | ||
|
||
[Test] | ||
public void GetHashCodeIsTheSame() | ||
{ | ||
var sut2 = new Tuple<int, string>(integer, stringy); | ||
|
||
sut.GetHashCode().ShouldEqual(sut2.GetHashCode()); | ||
} | ||
|
||
[Test] | ||
public void GetHashCodeIsDifferent() | ||
{ | ||
var sut2 = new Tuple<int, string>(integer + 1, stringy); | ||
|
||
sut.GetHashCode().ShouldNotEqual(sut2.GetHashCode()); | ||
} | ||
|
||
[Test] | ||
public void Equals() | ||
{ | ||
var sut2 = new Tuple<int, string>(integer, stringy); | ||
|
||
sut.Equals(sut2).ShouldBeTrue(); | ||
Equals(sut, sut2).ShouldBeTrue(); | ||
} | ||
|
||
[Test] | ||
public void NotEquals() | ||
{ | ||
var sut2 = new Tuple<int, string>(integer + 1, stringy); | ||
|
||
sut.Equals(sut2).ShouldBeFalse(); | ||
Equals(sut, sut2).ShouldBeFalse(); | ||
} | ||
} | ||
} |
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
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,65 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace LibGit2Sharp.Core.Compat | ||
{ | ||
/// <summary> | ||
/// Represents a 2-tuple, or pair. | ||
/// </summary> | ||
/// <typeparam name = "T1">The type of the tuple's first component.</typeparam> | ||
/// <typeparam name = "T2">The type of the tuple's second component.</typeparam> | ||
public class Tuple<T1, T2> | ||
{ | ||
private readonly KeyValuePair<T1, T2> kvp; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="Tuple{T1,T2}"/> class. | ||
/// </summary> | ||
/// <param name="item1">The value of the tuple's first component.</param> | ||
/// <param name="item2">The value of the tuple's second component.</param> | ||
public Tuple(T1 item1, T2 item2) | ||
{ | ||
kvp = new KeyValuePair<T1, T2>(item1, item2); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the value of the current <see cref = "Tuple{T1,T2}" /> object's second component. | ||
/// </summary> | ||
public T2 Item2 | ||
{ | ||
get { return kvp.Value; } | ||
} | ||
|
||
/// <summary> | ||
/// Gets the value of the current <see cref = "Tuple{T1,T2}" /> object's first component. | ||
/// </summary> | ||
public T1 Item1 | ||
{ | ||
get { return kvp.Key; } | ||
} | ||
|
||
/// <summary> | ||
/// Returns the hash code for the current <see cref = "Tuple{T1,T2}" /> object. | ||
/// </summary> | ||
/// <returns>A 32-bit signed integer hash code.</returns> | ||
public override int GetHashCode() | ||
{ | ||
return kvp.GetHashCode(); | ||
} | ||
|
||
/// <summary> | ||
/// Returns a value that indicates whether the current <see cref = "Tuple{T1,T2}" /> object is equal to a specified object. | ||
/// </summary> | ||
/// <param name = "obj">The object to compare with this instance.</param> | ||
/// <returns>true if the current instance is equal to the specified object; otherwise, false.</returns> | ||
public override bool Equals(object obj) | ||
{ | ||
if (!(obj is Tuple<T1, T2>)) | ||
{ | ||
return false; | ||
} | ||
return kvp.Equals(((Tuple<T1, T2>)obj).kvp); | ||
} | ||
|
||
|
||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using LibGit2Sharp.Core; | ||
using LibGit2Sharp.Core.Compat; | ||
|
||
namespace LibGit2Sharp | ||
{ | ||
|
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
using System; | ||
using LibGit2Sharp.Core; | ||
using LibGit2Sharp.Core.Compat; | ||
|
||
namespace LibGit2Sharp | ||
{ | ||
|
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
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