public OperationResult Generate(DateTime dateFrom, DateTime dateTo, GenderRequest gender) { OperationResult result; try { switch (_generationKind) { case GenerationKind.BirthNumber: BirthNumber bn = BirthNumber.OneRandom(dateFrom, dateTo, gender); result = WriteNumber(bn); break; case GenerationKind.DNumber: DNumber dn = DNumber.OneRandom(dateFrom, dateTo, gender); result = WriteNumber(dn); break; default: throw new ArgumentOutOfRangeException(); } } catch (NinException ex) { result = new OperationResult { Code = ex.Code, Message = ex.Message }; } return(result); }
public void ManyRandom_ReturnsRequestedNumber(int count) { List <DNumber> many = DNumber.ManyRandom(count).ToList(); Assert.IsNotNull(many); Assert.AreEqual(count, many.Count); }
public void Construct_Legal_PropertiesSet(string number) { DNumber dn = new DNumber(number); Assert.AreEqual("D-nummer", dn.Name); Assert.AreEqual(number, dn.Number); }
public void ManyRandom_TooManyRequested_ReturnsMaximumNumber() { List <DNumber> many = DNumber.ManyRandom(DNumber.PossibleLegalVariations + 123).ToList(); Assert.IsNotNull(many); Assert.AreEqual(DNumber.PossibleLegalVariations, many.Count); }
private void VerifyUnknownKindOfNumber(string number) { OrganizationNumber on = OrganizationNumber.Create(number); if (on != null) { ShowResult("Organisasjonsnummer", string.Format("'{0}' er et lovlig organisasjonsnummer.", number)); return; } BirthNumber bn = BirthNumber.Create(number); if (bn != null) { ShowResult("Fødselsnummer", string.Format("'{0}' er et lovlig fødselsnummer.", number)); return; } DNumber dn = DNumber.Create(number); if (dn != null) { ShowResult("D-nummer", string.Format("'{0}' er et lovlig D-nummer.", number)); return; } ShowResult("Identitetsnummer", string.Format("'{0}' gjenkjennes ikke. Det er verken organisasjonsnummer, fødselsnummer eller D-nummer.", number), true); }
/// <inheritdoc /> public INumber Pow(INumber a, INumber b) { TNumber internalA = InternaliseNumber(a); TNumber internalB = InternaliseNumber(b); return(CreateNumberFromHandle(DNumber.Pow(internalA.Handle, internalB.Handle))); }
/// <inheritdoc /> public INumber Pow <TOther>(INumber a, TOther b) { TNumber internalA = InternaliseNumber(a); float internalB = (float)System.Convert.ChangeType(b, typeof(float)); return(CreateNumberFromHandle(DNumber.Pow(internalA.Handle, internalB))); }
private static OperationResult ValidateAnyIdNumber(string number) { OrganizationNumber on = OrganizationNumber.Create(number); if (on != null) { return(new OperationResult { Code = Statuscode.Ok, Message = "Organization number" }); } BirthNumber bn = BirthNumber.Create(number); if (bn != null) { return(new OperationResult { Code = Statuscode.Ok, Message = "Birth number" }); } DNumber dn = DNumber.Create(number); if (dn != null) { return(new OperationResult { Code = Statuscode.Ok, Message = "D-number" }); } return(new OperationResult { Code = Statuscode.NoMatchFound, Message = "Neither organization number, birth number nor D-number." }); }
public OperationResult Generate(string pattern) { OperationResult result; try { switch (_generationKind) { case GenerationKind.OrganizationNumber: OrganizationNumber on = OrganizationNumber.OneRandom(pattern); result = WriteNumber(on); break; case GenerationKind.BirthNumber: BirthNumber bn = BirthNumber.OneRandom(pattern); result = WriteNumber(bn); break; case GenerationKind.DNumber: DNumber dn = DNumber.OneRandom(pattern); result = WriteNumber(dn); break; default: throw new ArgumentOutOfRangeException(); } } catch (NinException ex) { result = new OperationResult { Code = ex.Code, Message = ex.Message }; } return(result); }
public OperationResult Generate(int count) { OperationResult result; try { switch (_generationKind) { case GenerationKind.OrganizationNumber: if (count > 1) { IEnumerable <OrganizationNumber> ons = OrganizationNumber.ManyRandom(count); result = WriteList(ons.Select(x => x.Number)); } else { OrganizationNumber on = OrganizationNumber.OneRandom(); result = WriteNumber(on); } break; case GenerationKind.BirthNumber: if (count > 1) { IEnumerable <BirthNumber> bns = BirthNumber.ManyRandom(count); result = WriteList(bns.Select(x => x.Number)); } else { BirthNumber bn = BirthNumber.OneRandom(); result = WriteNumber(bn); } break; case GenerationKind.DNumber: if (count > 1) { IEnumerable <DNumber> dns = DNumber.ManyRandom(count); result = WriteList(dns.Select(x => x.Number)); } else { DNumber dn = DNumber.OneRandom(); result = WriteNumber(dn); } break; default: throw new ArgumentOutOfRangeException(); } } catch (NinException ex) { result = new OperationResult { Code = ex.Code, Message = ex.Message }; } return(result); }
public void OneRandom_InvalidCharacterInPattern_ThrowsException(string pattern) { var ex = Assert.Throws(typeof(NinException), () => DNumber.OneRandom(pattern)); NinException nex = ex as NinException; Assert.IsNotNull(nex); Assert.AreEqual(Statuscode.BadPattern, nex.Code); }
public void OneRandom_EmptyPattern_ThrowsException() { var ex = Assert.Throws(typeof(NinException), () => DNumber.OneRandom(string.Empty)); NinException nex = ex as NinException; Assert.IsNotNull(nex); Assert.AreEqual(Statuscode.PatternIsNullOrEmpty, nex.Code); }
public void OneRandom_NoWildcardInPattern_ThrowsException() { var ex = Assert.Throws(typeof(NinException), () => DNumber.OneRandom("01234567890")); NinException nex = ex as NinException; Assert.IsNotNull(nex); Assert.AreEqual(Statuscode.BadPattern, nex.Code); }
public void Create_Legal_ReturnsObjectWithPropertiesSet(string number) { DNumber dn = DNumber.Create(number); Assert.IsNotNull(dn); Assert.AreEqual("D-nummer", dn.Name); Assert.AreEqual(number, dn.Number); }
public void OneRandom_FromDateLaterThanToDate_ThrowsException() { var ex = Assert.Throws(typeof(NinException), () => DNumber.OneRandom(DateBasedIdNumber.LastPossible, DateBasedIdNumber.FirstPossible)); NinException nex = ex as NinException; Assert.IsNotNull(nex); Assert.AreEqual(Statuscode.BadDate, nex.Code); }
public void OneRandom_TwoCallsReturnsDifferentNumbers() { DNumber dNo1 = DNumber.OneRandom(); DNumber dNo2 = DNumber.OneRandom(); Assert.IsNotNull(dNo1); Assert.IsNotNull(dNo2); Assert.AreNotEqual(dNo1.Number, dNo2.Number); }
public void AllPossible_ReturnsAllPossibleVariations() { List <DNumber> allPossible = DNumber.AllPossible().ToList(); Assert.IsNotNull(allPossible); Assert.AreEqual(DNumber.PossibleLegalVariations, allPossible.Count); Assert.AreEqual("41015450051", allPossible[0].Number); Assert.AreEqual("71123999929", allPossible[DNumber.PossibleLegalVariations - 1].Number); }
public void OneRandom_SpecificGender_ReturnsOnlySpecifiedGender(GenderRequest gender, int expectedOddOrEven) { for (int index = 0; index < 10; ++index) { DNumber dNo = DNumber.OneRandom(DateBasedIdNumber.FirstPossible, DateBasedIdNumber.LastPossible, gender); Assert.IsNotNull(dNo); int oddOrEven = dNo.Number[8] & 1; Assert.AreEqual(expectedOddOrEven, oddOrEven); } }
private void VerifyDNumber(string number) { try { // ReSharper disable once UnusedVariable DNumber dn = new DNumber(number); ShowResult("D-nummer", string.Format("{0} er et lovlig D-nummer.", number)); } catch (NinException ex) { ShowResult("D-nummer", ex.Message, true); } }
public static void Main(string[] args) { DNumber a = new DNumber(1.0f).GetReverse(0); DNumber b = a * 2; DNDArray array = new DNDArray(new Util.NativeDataBuffer <double>(new double[] { 1, 2, 3, 4, 5, 6 }), new long[] { 2, 3 }); DNumber c = AD.Sum(array * b); Float64.DOps.reverseProp(new DNumber(1.0f).asADD, c.asADD); Console.WriteLine(b.A.Value); Console.ReadKey(); }
private static OperationResult ValidateDNumber(string number) { try { DNumber dNumber = new DNumber(number); return(new OperationResult { Code = Statuscode.Ok }); } catch (NinException ex) { return(new OperationResult { Code = ex.Code, Message = ex.Message }); } }
public CudaFloat32Number(DNumber numberHandle, CudaContext context) : base(numberHandle.Value) { if (numberHandle == null) { throw new ArgumentNullException(nameof(numberHandle)); } if (context == null) { throw new ArgumentNullException(nameof(context)); } Handle = numberHandle; CudaContext = context; _cudaContextDeviceId = CudaContext.DeviceId; }
public void OneRandom_SpecificYear_ReturnsValidIndividualNumber(GenderRequest gender) { int firstYear = DateBasedIdNumber.FirstPossible.Year; int lastYear = DateBasedIdNumber.LastPossible.Year; for (int year = firstYear; year < lastYear; ++year) { IEnumerable <int> legalIndividualNumbers = IndividualNumberProvider.GetLegalNumbers(year, gender); DateTime dateFrom = new DateTime(year, 1, 1); DateTime dateTo = new DateTime(year, 12, 31); DNumber dNumber = DNumber.OneRandom(dateFrom, dateTo, gender); if (null != dNumber) { int individualNumber = int.Parse(dNumber.Number.Substring(6, 3)); Assert.IsTrue(legalIndividualNumbers.Contains(individualNumber)); } } }
private void GenerateDNumber() { try { if (0 == comboBoxVaryUsing.SelectedIndex) { string pattern = textBoxPattern.Text.Trim(); DNumber dNo = string.IsNullOrEmpty(pattern) ? DNumber.OneRandom() : DNumber.OneRandom(pattern); ShowGenerated(dNo); } else { GenderRequest gender; switch (comboBoxGender.SelectedIndex) { case 1: gender = GenderRequest.Female; break; case 2: gender = GenderRequest.Male; break; default: gender = GenderRequest.Any; break; } DNumber dNo = DNumber.OneRandom(dateTimePickerFrom.Value, dateTimePickerTo.Value, gender); ShowGenerated(dNo); } } catch (NinException ex) { ShowResult("Feil", string.Format("Klarte ikke å generere D-nummer:\r\n{0}", ex.Message), true); } }
// Define a function whose derivative you need // F(x) = Sin(x^2 - Exp(x)) public static DNumber F(DNumber x) { return(Sin(x * x - Exp(x))); }
/// <inheritdoc /> protected override ADFloat32Number CreateNumberFromHandle(DNumber handle) { return(new ADFloat32Number(handle)); }
private void VerifyDNumber(string number) { try { // ReSharper disable once UnusedVariable DNumber dn = new DNumber(number); ShowResult("D-nummer", string.Format("{0} er et gyldig D-nummer.", number)); } catch (NinException ex) { ShowResult("D-nummer", ex.Message, true); } }
internal override void SetValue(float value) { base.SetValue(value); Handle = new DNumber(value); }
public void Create_Illegal_ReturnsNull(string number) { DNumber dn = DNumber.Create(number); Assert.IsNull(dn); }
public void OneRandom_GoodPattern_ReturnsValidNumber(string pattern) { Assert.DoesNotThrow(() => DNumber.OneRandom(pattern)); }
public void OneRandom_ReturnsValidNumber() { Assert.DoesNotThrow(() => DNumber.OneRandom()); }