public void StructTupleEqualityWithReferenceTypesInEquatableWrapper() { var o1 = new TestNonEquatable(1); var o2 = new TestNonEquatable(2); var o3 = new TestNonEquatable(3); StructTester.TestEquality( baseValue: StructTuple.Create(EquatableClass.Create(o1), EquatableClass.Create(o2)), equalValue: StructTuple.Create(EquatableClass.Create(o1), EquatableClass.Create(o2)), notEqualValues: new[] { StructTuple.Create(EquatableClass.Create(o1), EquatableClass.Create(o3)), StructTuple.Create(EquatableClass.Create(o2), EquatableClass.Create(o2)), StructTuple.Create(EquatableClass.Create(o2), EquatableClass.Create(o1)), StructTuple.Create <EquatableClass <TestNonEquatable>, EquatableClass <TestNonEquatable> >(null, o2), StructTuple.Create <EquatableClass <TestNonEquatable>, EquatableClass <TestNonEquatable> >(o1, null) }, eq: (left, right) => left == right, neq: (left, right) => left != right); StructTester.TestEquality( baseValue: StructTuple.Create <EquatableClass <TestNonEquatable>, EquatableClass <TestNonEquatable> >(o1, o2), equalValue: StructTuple.Create <EquatableClass <TestNonEquatable>, EquatableClass <TestNonEquatable> >(new TestNonEquatable(1), new TestNonEquatable(2)), notEqualValues: new[] { StructTuple.Create <EquatableClass <TestNonEquatable>, EquatableClass <TestNonEquatable> >(new TestNonEquatable(1), new TestNonEquatable(3)), StructTuple.Create <EquatableClass <TestNonEquatable>, EquatableClass <TestNonEquatable> >(new TestNonEquatable(2), new TestNonEquatable(2)), StructTuple.Create <EquatableClass <TestNonEquatable>, EquatableClass <TestNonEquatable> >(new TestNonEquatable(2), new TestNonEquatable(1)), StructTuple.Create <EquatableClass <TestNonEquatable>, EquatableClass <TestNonEquatable> >(null, null) }, eq: (left, right) => left == right, neq: (left, right) => left != right); }
private static void TestFingerprintEquality <TStruct>( Func <Fingerprint, TStruct> construct, Func <TStruct, TStruct, bool> eq, Func <TStruct, TStruct, bool> neq) where TStruct : struct, IEquatable <TStruct> { // SHA1 hash of "This is a sacrifice to the code coverage gods" Fingerprint baseValueHash; XAssert.IsTrue(Fingerprint.TryParse("64be6ae7b487e04701056542c4943e3cfe52280f", out baseValueHash)); TStruct baseValue = construct(baseValueHash); // The first four bytes of the hash should be part of the hash code. StructTester.TestEquality( baseValue: baseValue, equalValue: construct(baseValueHash), notEqualValues: Enumerable.Range(0, 4).Select(i => construct(TwiddleHashByte(baseValueHash, i))).ToArray(), eq: eq, neq: neq, skipHashCodeForNotEqualValues: false); // The remaining bytes do not impact the hash code, so we opt out of the hash check. StructTester.TestEquality( baseValue: baseValue, equalValue: construct(baseValueHash), notEqualValues: Enumerable.Range(4, FingerprintUtilities.FingerprintLength - 4).Select(i => construct(TwiddleHashByte(baseValueHash, i))).ToArray(), eq: eq, neq: neq, skipHashCodeForNotEqualValues: true); }
public void StructTupleEqualityWithReferenceTypes() { var o1 = new TestEquatable(1); var o2 = new TestEquatable(2); var o3 = new TestEquatable(3); StructTester.TestEquality( baseValue: StructTuple.Create(o1, o2), equalValue: StructTuple.Create(o1, o2), notEqualValues: new[] { StructTuple.Create(o1, o3), StructTuple.Create(o2, o2), StructTuple.Create(o2, o1), StructTuple.Create <TestEquatable, TestEquatable>(null, o2), StructTuple.Create <TestEquatable, TestEquatable>(o1, null) }, eq: (left, right) => left == right, neq: (left, right) => left != right); StructTester.TestEquality( baseValue: StructTuple.Create(o1, o2), equalValue: StructTuple.Create(new TestEquatable(1), new TestEquatable(2)), notEqualValues: new[] { StructTuple.Create(new TestEquatable(1), new TestEquatable(3)), StructTuple.Create(new TestEquatable(2), new TestEquatable(2)), StructTuple.Create(new TestEquatable(2), new TestEquatable(1)), StructTuple.Create <TestEquatable, TestEquatable>(null, null) }, eq: (left, right) => left == right, neq: (left, right) => left != right); }
public void AbsolutePathEquality() { StructTester.TestEquality( baseValue: new StringId(123), equalValue: new StringId(123), notEqualValues: new StringId[] { StringId.Invalid, new StringId(124) }, eq: (a, b) => a == b, neq: (a, b) => a != b); }
public void HierarchicalNameIdEquality() { StructTester.TestEquality( baseValue: new HierarchicalNameId(123), equalValue: new HierarchicalNameId(123), notEqualValues: new HierarchicalNameId[] { HierarchicalNameId.Invalid, new HierarchicalNameId(124) }, eq: (a, b) => a == b, neq: (a, b) => a != b); }
public void StructTupleEqualityWithEnumInEquatableWrapper() { StructTester.TestEquality( baseValue: StructTuple.Create <EquatableEnum <TestEnum>, EquatableEnum <TestEnum> >(TestEnum.A, TestEnum.B), equalValue: StructTuple.Create <EquatableEnum <TestEnum>, EquatableEnum <TestEnum> >(TestEnum.A, TestEnum.B), notEqualValues: new[] { StructTuple.Create <EquatableEnum <TestEnum>, EquatableEnum <TestEnum> >(TestEnum.B, TestEnum.A), StructTuple.Create <EquatableEnum <TestEnum>, EquatableEnum <TestEnum> >(TestEnum.A, TestEnum.A), StructTuple.Create <EquatableEnum <TestEnum>, EquatableEnum <TestEnum> >(TestEnum.C, TestEnum.C) }, eq: (left, right) => left == right, neq: (left, right) => left != right); }
public void StructTupleEquality() { StructTester.TestEquality( baseValue: StructTuple.Create(1, 2), equalValue: StructTuple.Create(1, 2), notEqualValues: new[] { StructTuple.Create(1, 3), StructTuple.Create(2, 2), StructTuple.Create(2, 1) }, eq: (left, right) => left == right, neq: (left, right) => left != right); }
public void RegexDescriptorEquality() { var stringTable = new StringTable(0); StructTester.TestEquality( baseValue: new RegexDescriptor(StringId.Create(stringTable, ".*"), RegexOptions.IgnoreCase), equalValue: new RegexDescriptor(StringId.Create(stringTable, ".*"), RegexOptions.IgnoreCase), notEqualValues: new[] { new RegexDescriptor(StringId.Create(stringTable, "[a-z]"), RegexOptions.IgnoreCase), new RegexDescriptor(StringId.Create(stringTable, ".*"), RegexOptions.ExplicitCapture), }, eq: (left, right) => left == right, neq: (left, right) => left != right); }
public void FileIdEquality() { var baseValue = new FileId(123, 456); StructTester.TestEquality( baseValue: baseValue, equalValue: baseValue, notEqualValues: new[] { new FileId(123, 457), new FileId(124, 456), }, eq: (a, b) => a == b, neq: (a, b) => a != b, skipHashCodeForNotEqualValues: false); }
public void MiniUsnRecordEquality() { var baseValue = new MiniUsnRecord(new FileId(123, 456), new Usn(789)); StructTester.TestEquality( baseValue: baseValue, equalValue: baseValue, notEqualValues: new[] { new MiniUsnRecord(new FileId(123, 456), new Usn(790)), new MiniUsnRecord(new FileId(123, 457), new Usn(789)), }, eq: (a, b) => a == b, neq: (a, b) => a != b, skipHashCodeForNotEqualValues: false); }
public void FileContentInfoEquality() { ContentHash hash1 = ContentHashingUtilities.CreateRandom(); ContentHash hash2 = hash1; ContentHash hash3 = ContentHashingUtilities.CreateRandom(); StructTester.TestEquality( baseValue: new FileContentInfo(hash1, 100), equalValue: new FileContentInfo(hash2, 100), notEqualValues: new[] { new FileContentInfo(hash3, 100), new FileContentInfo(hash2, 200), }, eq: (left, right) => left == right, neq: (left, right) => left != right); }
public void UsnRecordEquality() { var baseValue = new UsnRecord(new FileId(123, 456), new FileId(123, 457), new Usn(789), UsnChangeReasons.DataExtend); StructTester.TestEquality( baseValue: baseValue, equalValue: baseValue, notEqualValues: new[] { new UsnRecord(new FileId(124, 456), new FileId(123, 457), new Usn(789), UsnChangeReasons.DataExtend), new UsnRecord(new FileId(123, 457), new FileId(123, 457), new Usn(789), UsnChangeReasons.DataExtend), new UsnRecord(new FileId(123, 456), new FileId(123, 457), new Usn(790), UsnChangeReasons.DataExtend), new UsnRecord(new FileId(123, 456), new FileId(123, 457), new Usn(790), UsnChangeReasons.DataOverwrite), new UsnRecord(new FileId(123, 456), new FileId(123, 458), new Usn(789), UsnChangeReasons.DataExtend) }, eq: (a, b) => a == b, neq: (a, b) => a != b, skipHashCodeForNotEqualValues: false); }
public void FileArtifactEquality() { var pathTable = new PathTable(); AbsolutePath file1 = AbsolutePath.Create(pathTable, A("t", "file1.txt")); AbsolutePath file2 = AbsolutePath.Create(pathTable, A("t", "file2.txt")); StructTester.TestEquality( baseValue: FileArtifact.CreateSourceFile(file1), equalValue: FileArtifact.CreateSourceFile(file1), notEqualValues: new[] { FileArtifact.CreateSourceFile(file2), FileArtifact.CreateSourceFile(file2).CreateNextWrittenVersion(), FileArtifact.CreateSourceFile(file1).CreateNextWrittenVersion(), FileArtifact.CreateSourceFile(file1).CreateNextWrittenVersion().CreateNextWrittenVersion() }, eq: (left, right) => left == right, neq: (left, right) => left != right, skipHashCodeForNotEqualValues: true); }
public void PipFragmentEquality() { var pathTable = new PathTable(); StructTester.TestEquality( baseValue: PipFragment.FromString("mystring", pathTable.StringTable), equalValue: PipFragment.FromString("mystring", pathTable.StringTable), notEqualValues: new[] { PipFragment.FromString("MyString", pathTable.StringTable), PipFragment.FromAbsolutePathForTesting( FileArtifact.CreateSourceFile(AbsolutePath.Create(pathTable, A("t", "file1.txt")))), PipFragment.FromAbsolutePathForTesting( FileArtifact.CreateSourceFile(AbsolutePath.Create(pathTable, A("t", "file1.txt"))).CreateNextWrittenVersion()), PipFragment.CreateNestedFragment( PipDataBuilder.CreatePipData(pathTable.StringTable, " ", PipDataFragmentEscaping.CRuntimeArgumentRules)) }, eq: (left, right) => left == right, neq: (left, right) => left != right); }
public void ContentHashWithOriginEquality() { ContentHash hashA = ContentHashingUtilities.CreateRandom(); ContentHash hashB = ContentHashingUtilities.CreateRandom(); FileContentInfo contentInfoA = new FileContentInfo(hashA, 123); FileContentInfo contentInfoB = new FileContentInfo(hashB, 123); VersionedFileIdentity identityA = new VersionedFileIdentity( volumeSerialNumber: 1, fileId: new FileId(2, 3), usn: new Usn(4), kind: VersionedFileIdentity.IdentityKind.StrongUsn); VersionedFileIdentity identityB = new VersionedFileIdentity( volumeSerialNumber: 2, fileId: new FileId(3, 4), usn: new Usn(5), kind: VersionedFileIdentity.IdentityKind.StrongUsn); StructTester.TestEquality( new FileContentTableExtensions.VersionedFileIdentityAndContentInfoWithOrigin( new VersionedFileIdentityAndContentInfo(identityA, contentInfoA), FileContentTableExtensions.ContentHashOrigin.NewlyHashed), equalValue: new FileContentTableExtensions.VersionedFileIdentityAndContentInfoWithOrigin( new VersionedFileIdentityAndContentInfo(identityA, contentInfoA), FileContentTableExtensions.ContentHashOrigin.NewlyHashed), notEqualValues: new[] { new FileContentTableExtensions.VersionedFileIdentityAndContentInfoWithOrigin( new VersionedFileIdentityAndContentInfo(identityA, contentInfoA), FileContentTableExtensions.ContentHashOrigin.Cached), new FileContentTableExtensions.VersionedFileIdentityAndContentInfoWithOrigin( new VersionedFileIdentityAndContentInfo(identityB, contentInfoA), FileContentTableExtensions.ContentHashOrigin.NewlyHashed), new FileContentTableExtensions.VersionedFileIdentityAndContentInfoWithOrigin( new VersionedFileIdentityAndContentInfo(identityA, contentInfoB), FileContentTableExtensions.ContentHashOrigin.NewlyHashed), }, eq: (a, b) => a == b, neq: (a, b) => a != b); }
public void FileArtifactEquality() { var pathTable = new PathTable(); FileArtifact file1 = FileArtifact.CreateSourceFile(AbsolutePath.Create(pathTable, A("t", "file1.txt"))); FileArtifact file2 = FileArtifact.CreateSourceFile(AbsolutePath.Create(pathTable, A("t", "file2.txt"))); StructTester.TestEquality( baseValue: FileArtifactWithAttributes.Create(file1, FileExistence.Required), equalValue: FileArtifactWithAttributes.Create(file1, FileExistence.Required), notEqualValues: new[] { FileArtifactWithAttributes.Create(file1, FileExistence.Optional), FileArtifactWithAttributes.Create(file1, FileExistence.Optional).CreateNextWrittenVersion(), FileArtifactWithAttributes.Create(file2, FileExistence.Temporary), FileArtifactWithAttributes.Create(file2, FileExistence.Temporary).CreateNextWrittenVersion(), FileArtifactWithAttributes.Create(file1, FileExistence.Required).CreateNextWrittenVersion(), FileArtifactWithAttributes.Create(file1, FileExistence.Required).CreateNextWrittenVersion().CreateNextWrittenVersion(), FileArtifactWithAttributes.Create(file1.CreateNextWrittenVersion(), FileExistence.Required) }, eq: (left, right) => left == right, neq: (left, right) => left != right, skipHashCodeForNotEqualValues: true); }