Fixed tests after refactoring storage
This commit is contained in:
parent
0f5735f713
commit
91b3be8adb
@ -0,0 +1,40 @@
|
||||
/*
|
||||
Copyright 2014 Alex Dyachenko
|
||||
|
||||
This file is part of the MPIR Library.
|
||||
|
||||
The MPIR Library is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 3 of the License, or (at
|
||||
your option) any later version.
|
||||
|
||||
The MPIR Library 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 Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the MPIR Library. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace MPIR.Tests.HugeIntTests
|
||||
{
|
||||
[TestClass]
|
||||
public class Assignment
|
||||
{
|
||||
[TestMethod]
|
||||
public void AssignCopy()
|
||||
{
|
||||
using (var a = new HugeInt("-222509832503450298345029835740293845720"))
|
||||
using (var b = new HugeInt())
|
||||
{
|
||||
b.Value = a;
|
||||
Assert.AreEqual("-222509832503450298345029835740293845720", b.ToString());
|
||||
}
|
||||
}
|
||||
//more tests coming here
|
||||
}
|
||||
}
|
@ -29,15 +29,11 @@ namespace MPIR.Tests
|
||||
internal static class Accessors
|
||||
{
|
||||
private static readonly ConstructorInfo _intPtrConstructor;
|
||||
private static readonly FieldInfo _getNumberOfLimbsAllocated;
|
||||
private static readonly FieldInfo _getNumberOfLimbsUsed;
|
||||
private static readonly FieldInfo _getLimbs;
|
||||
private static readonly FieldInfo _getValue;
|
||||
|
||||
static Accessors()
|
||||
{
|
||||
_getNumberOfLimbsAllocated = GetAccessor("_numberOfLimbsAllocated");
|
||||
_getNumberOfLimbsUsed = GetAccessor("_numberOfLimbsUsed");
|
||||
_getLimbs = GetAccessor("_limbs");
|
||||
_getValue = GetAccessor("_value");
|
||||
|
||||
_intPtrConstructor = typeof(IntPtr).GetConstructor(new[] { Type.GetType("System.Void*") });
|
||||
}
|
||||
@ -49,17 +45,40 @@ namespace MPIR.Tests
|
||||
|
||||
public static int NumberOfLimbsAllocated(this HugeInt x)
|
||||
{
|
||||
return (int)_getNumberOfLimbsAllocated.GetValue(x);
|
||||
if (x._value() == IntPtr.Zero)
|
||||
return 0;
|
||||
|
||||
unsafe
|
||||
{
|
||||
return ((int*)x._value().ToPointer())[0];
|
||||
}
|
||||
}
|
||||
|
||||
public static int NumberOfLimbsUsed(this HugeInt x)
|
||||
{
|
||||
return (int)_getNumberOfLimbsUsed.GetValue(x);
|
||||
if (x._value() == IntPtr.Zero)
|
||||
return 0;
|
||||
|
||||
unsafe
|
||||
{
|
||||
return ((int*)x._value().ToPointer())[1];
|
||||
}
|
||||
}
|
||||
|
||||
public static IntPtr Limbs(this HugeInt x)
|
||||
{
|
||||
return (IntPtr)_intPtrConstructor.Invoke(new object[] { _getLimbs.GetValue(x) });
|
||||
if (x._value() == IntPtr.Zero)
|
||||
return IntPtr.Zero;
|
||||
|
||||
unsafe
|
||||
{
|
||||
return new IntPtr(((void**)x._value().ToPointer())[1]);
|
||||
}
|
||||
}
|
||||
|
||||
public static IntPtr _value(this HugeInt x)
|
||||
{
|
||||
return (IntPtr)_intPtrConstructor.Invoke(new object[] { _getValue.GetValue(x) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
@ -33,6 +34,7 @@
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@ -42,6 +44,7 @@
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
@ -51,6 +54,7 @@
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@ -60,6 +64,7 @@
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<OutputPath>bin\x86\Release\</OutputPath>
|
||||
@ -69,6 +74,7 @@
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
@ -87,6 +93,7 @@
|
||||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="HugeIntTests\Arithmetic.cs" />
|
||||
<Compile Include="HugeIntTests\Assignment.cs" />
|
||||
<Compile Include="HugeIntTests\ObjectOverrides.cs" />
|
||||
<Compile Include="Utilities\Accessors.cs" />
|
||||
<Compile Include="HugeIntTests\ConstructionAndDisposal.cs" />
|
||||
|
@ -237,6 +237,17 @@ namespace MPIR
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Properties
|
||||
|
||||
void HugeInt::Value::set(HugeInt^ a)
|
||||
{
|
||||
THIS_PTR;
|
||||
mpz_set(src_this, a->_value);
|
||||
SAVE_THIS;
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Arithmetic
|
||||
|
||||
HugeInt^ HugeInt::operator+(HugeInt^ destination, HugeInt^ source)
|
||||
|
@ -74,6 +74,12 @@ namespace MPIR
|
||||
virtual String^ ToString() override;
|
||||
String^ ToString(int base);
|
||||
|
||||
//properties
|
||||
property HugeInt^ Value
|
||||
{
|
||||
void set(HugeInt^ value);
|
||||
}
|
||||
|
||||
//arithmetic
|
||||
static HugeInt^ operator+(HugeInt^ destination, HugeInt^ source);
|
||||
DECLARE_VOID_FROM_MPZ_OR_UI(Add)
|
||||
|
Loading…
Reference in New Issue
Block a user