Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Code/Epic.Linq/Expressions/Relational/Scalar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public abstract class Scalar: VisitableBase, IEquatable<Scalar>
/// <param name='type'>
/// The scalar <see cref="ScalarType"/>.
/// </param>
public Scalar (ScalarType type)
internal Scalar (ScalarType type)
{
this._type = type;
}
Expand All @@ -55,6 +55,13 @@ public Scalar (ScalarType type)
/// </value>
public ScalarType Type { get { return this._type; } }

public abstract override int GetHashCode ();

public override bool Equals (object obj)
{
return Equals (obj as Scalar);
}

#region IEquatable[Scalar] implementation
/// <summary>
/// Determines whether the specified <see cref="Scalar"/> is equal to the current <see cref="Epic.Linq.Expressions.Relational.Scalar"/>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<OutputType>Library</OutputType>
<RootNamespace>Epic.Linq</RootNamespace>
<AssemblyName>Epic.Linq.UnitTests</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -102,5 +101,6 @@
<Compile Include="Fakes\FakeRelationFunction.cs" />
<Compile Include="Expressions\Relational\ScalarFunctionQA.cs" />
<Compile Include="Fakes\FakeScalarFunction.cs" />
<Compile Include="Fakes\FakeScalar.cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,59 @@ public void FunctionEquals_toOtherScalarType_isFalse(string name)
{
// arrange:
ScalarFunction func1 = new FakeScalarFunction(name);
Scalar scalar = GenerateStrictMock<Scalar>(ScalarType.Constant);

Scalar scalar = new FakeScalar(ScalarType.Constant);
// act:
bool result = func1.Equals(scalar);

bool result1 = func1.Equals(scalar);
// assert:
// here the FakeScalarFunction.Equals is called, so the result depends on the implementation
Assert.IsFalse(result);
Assert.IsFalse(result1);
}

[TestCase("test")]
public void FunctionEquals_FromObjectReferenceToEqualInstance_isTrue(string name)
{
// arrange:
ScalarFunction func1 = new FakeScalarFunction(name);
ScalarFunction func2 = new FakeScalarFunction(name);
Scalar scalar = func2;
object obj = func2;

// act:
bool result1 = func1.Equals (func2);
bool result2 = func1.Equals (scalar);
bool result3 = func1.Equals (obj);
bool result4 = scalar.Equals(func1);
bool result5 = obj.Equals (func1);

// assert:
Assert.IsTrue (result1);
Assert.IsTrue (result2);
Assert.IsTrue (result3);
Assert.IsTrue (result4);
Assert.IsTrue (result5);


}

[TestCase("test")]
public void FunctionEquals_withOtherReference_isFalse(string name)
{
// arrange:
ScalarFunction func1 = new FakeScalarFunction(name);
Scalar scalar = new FakeScalar(ScalarType.Function);
object obj = scalar;

// act:
bool result1 = func1.Equals(scalar);
bool result2 = func1.Equals(obj);
bool result3 = obj.Equals (func1);
bool result4 = scalar.Equals(func1);

// assert:
Assert.IsFalse (result1);
Assert.IsFalse (result2);
Assert.IsFalse (result3);
Assert.IsFalse (result4);
}

}
Expand Down
61 changes: 61 additions & 0 deletions Code/UnitTests/Epic.Linq.UnitTests/Fakes/FakeScalar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// FakeScalar.cs
//
// Author:
// Marco <${AuthorEmail}>
//
// Copyright (c) 2010-2011 Giacomo Tesio
//
// This file is part of Epic.NET.
//
// Epic.NET is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Epic.NET is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
using System;
using Epic.Linq.Expressions.Relational;

namespace Epic.Linq.Fakes
{
[Serializable]
public sealed class FakeScalar: Scalar
{
private static int count = 0;
private readonly int id;
public FakeScalar (ScalarType type): base(type)
{
id = count++;
}

public override int GetHashCode()
{
return id;
}

public override bool Equals(Scalar other)
{
return Equals (other as FakeScalar);
}

public bool Equals(FakeScalar other)
{
if (null == other) return false;
return this.id == other.id;
}

public override TResult Accept<TResult> (Epic.Linq.Expressions.IVisitor<TResult> visitor, Epic.Linq.Expressions.IVisitContext context)
{
throw new NotImplementedException();
}
}
}