static long DifferenceCalculation(string inputFile) { var parser = new LongParser(); var numbers = parser.ReadData(inputFile).ToList(); return(DifferenceCalculation(numbers)); }
public static Either <TLeft, long> ParseToLong <TLeft>( this Either <TLeft, string> source, IFormatProvider provider, TLeft left) { return(source.FlatMap(x => LongParser.Parse <TLeft>(x, provider, left))); }
static int MagicCalculation(string inputFile) { var parser = new LongParser(); var numbers = parser.ReadData(inputFile).ToList(); return(MagicCalculation(numbers)); }
protected internal override object CreateValue(IndexReader reader, object entryKey) { Entry entry = (Entry)entryKey; System.String field = entry.field; LongParser parser = (LongParser)entry.custom; long[] retArray = new long[reader.MaxDoc()]; TermDocs termDocs = reader.TermDocs(); TermEnum termEnum = reader.Terms(new Term(field)); try { do { Term term = termEnum.Term(); if (term == null || (object)term.Field() != (object)field) { break; } long termval = parser.ParseLong(term.Text()); termDocs.Seek(termEnum); while (termDocs.Next()) { retArray[termDocs.Doc()] = termval; } }while (termEnum.Next()); } finally { termDocs.Close(); termEnum.Close(); } return(retArray); }
public static Either <TLeft, long> ParseToLong <TLeft>( this Either <TLeft, string> source, NumberStyles style, TLeft left) { return(source.FlatMap(x => LongParser.Parse <TLeft>(x, style, left))); }
public static long FindEncryptionWeakness(string inputFile, long expectedSum) { var parser = new LongParser(); var list = parser.ReadData(inputFile).ToList(); return(SumMinMax(FindContiniousSum(list, expectedSum))); }
public static Either <TLeft, long> ParseToLong <TLeft>( this string source, NumberStyles style, IFormatProvider provider, TLeft left) { return(LongParser.Parse <TLeft>(source, style, provider, left)); }
public static long FindFirstMismatch(string inputFile, int preambleLength) { var parser = new LongParser(); var numbers = parser.ReadData(inputFile).ToList(); var result = numbers.Select((x, i) => new Tuple <long, bool>(x, IsSumInList(FindSubList(numbers, i, preambleLength), x))); return(result.First(x => !x.Item2).Item1); }
static int Second(string inputFile) { var parser = new LongParser(); var numbers = parser.ReadData(inputFile).ToList(); var differences = numbers.Differences3(); return(differences.Count(d => d > 0)); }
public static int?GuessAgeOrNull(string number, DateTime?overrideNow = null) { var today = overrideNow ?? DateTime.Today; var now = LongParser.ParseOrNull(today.ToString("yyyyMMdd")); var then = LongParser.ParseOrNull(GuessBirthDate(number, today)?.ToString("yyyyMMdd")); return(now.HasValue && then.HasValue ? (int)Math.Floor(((decimal)now.Value - then.Value) / 10000m) : (int?)null); }
public async Task <ClashDelayResponse> GetClashProxyDelay(string name, int timeout = 5000, string testUrl = "http://www.gstatic.com/generate_204") { string url = string.Format(API_PROXIES_DELAY, Uri.EscapeDataString(name)); var dict = new Dictionary <string, dynamic>(); dict.Add("timeout", Convert.ToString(timeout)); dict.Add("url", testUrl); var result = await GetAsync <ClashDelayResponse>(url, dict); result.DelayLong = LongParser.Parse(result.Delay); return(result); }
static FieldCache_Fields() { DEFAULT = new FieldCacheImpl(); DEFAULT_BYTE_PARSER = new AnonymousClassByteParser(); DEFAULT_SHORT_PARSER = new AnonymousClassShortParser(); DEFAULT_INT_PARSER = new AnonymousClassIntParser(); DEFAULT_FLOAT_PARSER = new AnonymousClassFloatParser(); DEFAULT_LONG_PARSER = new AnonymousClassLongParser(); DEFAULT_DOUBLE_PARSER = new AnonymousClassDoubleParser(); NUMERIC_UTILS_INT_PARSER = new AnonymousClassIntParser1(); NUMERIC_UTILS_FLOAT_PARSER = new AnonymousClassFloatParser1(); NUMERIC_UTILS_LONG_PARSER = new AnonymousClassLongParser1(); NUMERIC_UTILS_DOUBLE_PARSER = new AnonymousClassDoubleParser1(); }
public static Maybe <long> ParseToLong(this Maybe <string> source, NumberStyles style) { return(source.FlatMap(x => LongParser.Parse(x, style))); }
public static Maybe <long> ParseToLong(this string source, NumberStyles style, IFormatProvider provider) { return(LongParser.Parse(source, style, provider)); }
public static Maybe <long> ParseToLong(this string source, NumberStyles style) { return(LongParser.Parse(source, style)); }
static ExtendedFieldCacheImpl() { LONG_PARSER = new AnonymousClassLongParser(); DOUBLE_PARSER = new AnonymousClassDoubleParser(); }
// inherit javadocs public virtual long[] GetLongs(IndexReader reader, System.String field, LongParser parser) { return (long[]) longsCache.Get(reader, new Entry(field, parser)); }
internal LongComparator(int numHits, System.String field, Lucene.Net.Search.Parser parser) { values = new long[numHits]; this.field = field; this.parser = (LongParser) parser; }
public void GetPolynomialDerivativeTest_IntegerFraction() { var polynomialText = "1/2*x^5+3/4*x^4-2/7*x^3+5/3*x^2+1/5*x+9"; var polynomialDerivativeText = "5/2*x^4+3*x^3-6/7*x^2+10/3*x+1/5"; var variableName = "x"; var integerDomain = new IntegerDomain(); var longDomain = new LongDomain(); var bigIntegerDomain = new BigIntegerDomain(); var integerParser = new IntegerParser <string>(); var longParser = new LongParser <string>(); var bigIntegerParser = new BigIntegerParser <string>(); var longConversion = new LongToIntegerConversion(); var bigIntegerConversion = new BigIntegerToIntegerConversion(); var integerFractionConversion = new ElementFractionConversion <int>(integerDomain); var longfractionConversion = new OuterElementFractionConversion <int, long>(longConversion, longDomain); var bigIntegerfractionConversion = new OuterElementFractionConversion <int, BigInteger>(bigIntegerConversion, bigIntegerDomain); var integerFractionField = new FractionField <int>(integerDomain); var longFractionField = new FractionField <long>(longDomain); var bigIntegerFractionField = new FractionField <BigInteger>(bigIntegerDomain); // Coeficientes inteiros var integerPolynomial = TestsHelper.ReadFractionalCoeffsUnivarPol <int, IntegerDomain>( polynomialText, integerDomain, integerParser, integerFractionConversion, variableName); var integerPolynomialDerivative = TestsHelper.ReadFractionalCoeffsUnivarPol <int, IntegerDomain>( polynomialDerivativeText, integerDomain, integerParser, integerFractionConversion, variableName); var integerActualPolDerivative = integerPolynomial.GetPolynomialDerivative(integerFractionField); Assert.AreEqual(integerPolynomialDerivative, integerActualPolDerivative); // Coeficientes longos var longPolynomial = TestsHelper.ReadFractionalCoeffsUnivarPol <long, LongDomain>( polynomialText, longDomain, longParser, longfractionConversion, variableName); var longPolynomialDerivative = TestsHelper.ReadFractionalCoeffsUnivarPol <long, LongDomain>( polynomialDerivativeText, longDomain, longParser, longfractionConversion, variableName); var longActualPolDerivative = longPolynomial.GetPolynomialDerivative(longFractionField); Assert.AreEqual(longPolynomialDerivative, longActualPolDerivative); var bigIntegerPolynomial = TestsHelper.ReadFractionalCoeffsUnivarPol <BigInteger, BigIntegerDomain>( polynomialText, bigIntegerDomain, bigIntegerParser, bigIntegerfractionConversion, variableName); var bigIntegerPolynomialDerivative = TestsHelper.ReadFractionalCoeffsUnivarPol <BigInteger, BigIntegerDomain>( polynomialDerivativeText, bigIntegerDomain, bigIntegerParser, bigIntegerfractionConversion, variableName); var bigIntegerActualPolDerivative = bigIntegerPolynomial.GetPolynomialDerivative(bigIntegerFractionField); Assert.AreEqual(bigIntegerPolynomialDerivative, bigIntegerActualPolDerivative); }
// inherit javadocs public virtual long[] GetLongs(IndexReader reader, System.String field, LongParser parser) { return((long[])longsCache.Get(reader, new Entry(field, parser))); }
public void PowerTest_FractionPolynomial() { var integerDomain = new IntegerDomain(); var longDomain = new LongDomain(); var bigIntegerDomain = new BigIntegerDomain(); var variableName = "x"; var integerPolynomialField = new UnivarPolynomEuclideanDomain <Fraction <int> >( variableName, new FractionField <int>(integerDomain)); var longPolynomialField = new UnivarPolynomEuclideanDomain <Fraction <long> >( variableName, new FractionField <long>(longDomain)); var bigIntegerPolynomialField = new UnivarPolynomEuclideanDomain <Fraction <BigInteger> >( variableName, new FractionField <BigInteger>(bigIntegerDomain)); // Leitores var integerParser = new IntegerParser <string>(); var longParser = new LongParser <string>(); var bigIntegerParser = new BigIntegerParser <string>(); var integerConversion = new OuterElementFractionConversion <int, int>(new ElementToElementConversion <int>(), integerDomain); var longToIntegerConversion = new OuterElementFractionConversion <int, long>(new LongToIntegerConversion(), longDomain); var bigIntegerToIntegerConversion = new OuterElementFractionConversion <int, BigInteger>(new BigIntegerToIntegerConversion(), bigIntegerDomain); var intPowers = new int[3] { 2, 3, 4 }; var longPowers = new long[3] { 2, 3, 4 }; var bigIntPowers = new BigInteger[3] { 2, 3, 4 }; var polynomialsTexts = new string[3] { "1/3*x^3-2/3*x^2+3/2*x-1/2", "2*x^2+4/3*x+4/9", "7/5*x+1" }; var expectedPolinomialsTexts = new string[3] { "1/9*x^6-4/9*x^5+13/9*x^4-7/3*x^3+35/12*x^2-3/2*x+1/4", "8*x^6+16*x^5+16*x^4+256/27*x^3+32/9*x^2+64/81*x+64/729", "2401/625*x^4+1372/125*x^3+294/25*x^2+28/5*x+1" }; // Coeficientes inteiros. for (int i = 0; i < 3; ++i) { var polynomialValue = TestsHelper.ReadFractionalCoeffsUnivarPol( polynomialsTexts[i], integerDomain, integerParser, integerConversion, variableName); var expectedPolynomial = TestsHelper.ReadFractionalCoeffsUnivarPol( expectedPolinomialsTexts[i], integerDomain, integerParser, integerConversion, variableName); var actualPolynomial = MathFunctions.Power(polynomialValue, intPowers[i], integerPolynomialField); Assert.AreEqual(expectedPolynomial, actualPolynomial); } // Coeficientes longos. for (int i = 0; i < 3; ++i) { var polynomialValue = TestsHelper.ReadFractionalCoeffsUnivarPol( polynomialsTexts[i], longDomain, longParser, longToIntegerConversion, variableName); var expectedPolynomial = TestsHelper.ReadFractionalCoeffsUnivarPol( expectedPolinomialsTexts[i], longDomain, longParser, longToIntegerConversion, variableName); var actualPolynomial = MathFunctions.Power(polynomialValue, intPowers[i], longPolynomialField); Assert.AreEqual(expectedPolynomial, actualPolynomial); } // Coeficientes correspondentes a inteiros de precisão arbitrária. for (int i = 0; i < 3; ++i) { var polynomialValue = TestsHelper.ReadFractionalCoeffsUnivarPol( polynomialsTexts[i], bigIntegerDomain, bigIntegerParser, bigIntegerToIntegerConversion, variableName); var expectedPolynomial = TestsHelper.ReadFractionalCoeffsUnivarPol( expectedPolinomialsTexts[i], bigIntegerDomain, bigIntegerParser, bigIntegerToIntegerConversion, variableName); var actualPolynomial = MathFunctions.Power(polynomialValue, intPowers[i], bigIntegerPolynomialField); Assert.AreEqual(expectedPolynomial, actualPolynomial); } }
public void GetPolynomialDerivativeTest_SimpleInteger() { // Representação dos polinómios. var polynomText = "x^1000-2*x^550+1000*x^10+50"; var polDerivativeText = "1000*x^999-1100*x^549+10000*x^9"; var variableName = "x"; // Estabelece os domínios. var integerDomain = new IntegerDomain(); var longDomain = new LongDomain(); var bigIntegerDomain = new BigIntegerDomain(); // Estabelece os conversores. var integerToIntegerConv = new ElementToElementConversion <int>(); var integerToLongConv = new LongToIntegerConversion(); var integerToBigIntegerConvsersion = new BigIntegerToIntegerConversion(); // Estabelece os leitores individuais. var integerParser = new IntegerParser <string>(); var longParser = new LongParser <string>(); var bigIntegerParser = new BigIntegerParser <string>(); // Estabelece os polinómios. var integerPolynomial = TestsHelper.ReadUnivarPolynomial( polynomText, integerDomain, integerParser, integerToIntegerConv, variableName); var integerExpectedPolynomial = TestsHelper.ReadUnivarPolynomial( polDerivativeText, integerDomain, integerParser, integerToIntegerConv, variableName); var integerActualDerivative = integerPolynomial.GetPolynomialDerivative(integerDomain); // Verifica se os polinómios são válidos. Assert.AreEqual(integerExpectedPolynomial, integerActualDerivative); // Estabelece os polinómios. var longPolynomial = TestsHelper.ReadUnivarPolynomial( polynomText, longDomain, longParser, integerToLongConv, variableName); var longExpectedPolynomial = TestsHelper.ReadUnivarPolynomial( polDerivativeText, longDomain, longParser, integerToLongConv, variableName); var longActualDerivative = longPolynomial.GetPolynomialDerivative(longDomain); // Verifica se os polinómios são válidos. Assert.AreEqual(longExpectedPolynomial, longActualDerivative); // Estabelece os polinómios. var bigIntegerPolynomial = TestsHelper.ReadUnivarPolynomial( polynomText, bigIntegerDomain, bigIntegerParser, integerToBigIntegerConvsersion, variableName); var bigIntegerExpectedPolynomial = TestsHelper.ReadUnivarPolynomial( polDerivativeText, bigIntegerDomain, bigIntegerParser, integerToBigIntegerConvsersion, variableName); var bigIntegerActualDerivative = bigIntegerPolynomial.GetPolynomialDerivative(bigIntegerDomain); // Verifica se os polinómios são válidos. Assert.AreEqual(bigIntegerExpectedPolynomial, bigIntegerActualDerivative); }
public void GetPolynomialDerivativeTest_IntegerPolynomialAsCoefficients() { var polynomialText = "(y^2+y+1)*x^3-2*x^2*y+x*(y^5-3)+4"; var polynomialDerivativeText = "3*(y^2+y+1)*x^2-4*y*x+y^5-3"; var variableName = "x"; var coeffsVariableName = "y"; // Os domínios responsáveis pelas operações sobre os inteiros. var integerDomain = new IntegerDomain(); var longDomain = new LongDomain(); var bigIntegerDomain = new BigIntegerDomain(); // Os leitore sde inteiros var integerParser = new IntegerParser <string>(); var longParser = new LongParser <string>(); var bigIntegerParser = new BigIntegerParser <string>(); // Definição das conversões. var integerConversion = new ElementToElementConversion <int>(); var longConversion = new LongToIntegerConversion(); var bigIntegerConversion = new BigIntegerToIntegerConversion(); var integerPolConvertion = new UnivarPolynomNormalFormToIntegerConversion <int>( coeffsVariableName, integerConversion, integerDomain); var longPolConvertion = new UnivarPolynomNormalFormToIntegerConversion <long>( coeffsVariableName, longConversion, longDomain); var bigIntegerPolConvertion = new UnivarPolynomNormalFormToIntegerConversion <BigInteger>( coeffsVariableName, bigIntegerConversion, bigIntegerDomain); // Definição dos anéis polinomiais. var integerPolynomialRing = new UnivarPolynomRing <int>(coeffsVariableName, integerDomain); var longPolynomialRing = new UnivarPolynomRing <long>(coeffsVariableName, longDomain); var bigIntegerPolynomialRing = new UnivarPolynomRing <BigInteger>(coeffsVariableName, bigIntegerDomain); // Definição dos leitores polinomiais. var integerPolynomialParser = new UnivarPolNormalFormParser <int>( coeffsVariableName, integerConversion, integerParser, integerDomain); var longPolynomialParser = new UnivarPolNormalFormParser <long>( coeffsVariableName, longConversion, longParser, longDomain); var bigIntegerPolynomialParser = new UnivarPolNormalFormParser <BigInteger>( coeffsVariableName, bigIntegerConversion, bigIntegerParser, bigIntegerDomain); // Definição dos testes. var integerPolynomial = TestsHelper.ReadUnivarPolynomial <UnivariatePolynomialNormalForm <int> >( polynomialText, integerPolynomialRing, integerPolynomialParser, integerPolConvertion, variableName); var integerExpectedPol = TestsHelper.ReadUnivarPolynomial <UnivariatePolynomialNormalForm <int> >( polynomialDerivativeText, integerPolynomialRing, integerPolynomialParser, integerPolConvertion, variableName); var integerActualPlynomial = integerPolynomial.GetPolynomialDerivative(integerPolynomialRing); Assert.AreEqual(integerExpectedPol, integerActualPlynomial); var longPolynomial = TestsHelper.ReadUnivarPolynomial <UnivariatePolynomialNormalForm <long> >( polynomialText, longPolynomialRing, longPolynomialParser, longPolConvertion, variableName); var longExpectedPol = TestsHelper.ReadUnivarPolynomial <UnivariatePolynomialNormalForm <long> >( polynomialDerivativeText, longPolynomialRing, longPolynomialParser, longPolConvertion, variableName); var longActualPlynomial = longPolynomial.GetPolynomialDerivative(longPolynomialRing); Assert.AreEqual(longExpectedPol, longActualPlynomial); var bigIntegerPolynomial = TestsHelper.ReadUnivarPolynomial <UnivariatePolynomialNormalForm <BigInteger> >( polynomialText, bigIntegerPolynomialRing, bigIntegerPolynomialParser, bigIntegerPolConvertion, variableName); var bigIntegerExpectedPol = TestsHelper.ReadUnivarPolynomial <UnivariatePolynomialNormalForm <BigInteger> >( polynomialDerivativeText, bigIntegerPolynomialRing, bigIntegerPolynomialParser, bigIntegerPolConvertion, variableName); var bigIntegerActualPlynomial = bigIntegerPolynomial.GetPolynomialDerivative(bigIntegerPolynomialRing); Assert.AreEqual(bigIntegerExpectedPol, bigIntegerExpectedPol); }
public static Maybe <long> ParseToLong(this Maybe <string> source, NumberStyles style, IFormatProvider provider) { return(source.FlatMap(x => LongParser.Parse(x, style, provider))); }
public static Maybe <long> ParseToLong(this string source) { return(LongParser.Parse(source)); }
public void GetPolynomialDerivativeTest_IntegerMatrix() { // Os valores a serem lidos var polynomialText = "[[1,2],[3,4]]*x^2-[[1,0],[0,1]]*x+[[7,6],[9,8]]"; var polynomialDerivativeText = "[[2,4],[6,8]]*x+[[-1,0],[0,-1]]"; var variableName = "x"; var arrayDelimiters = new Dictionary <string, string>(); arrayDelimiters.Add("left_bracket", "right_bracket"); // Os domínios responsáveis sobre as operações sobre os inteiros. var integerDomain = new IntegerDomain(); var longDomain = new LongDomain(); var bigIntegerDomain = new BigIntegerDomain(); // Os leitore sde inteiros var integerParser = new IntegerParser <string>(); var longParser = new LongParser <string>(); var bigIntegerParser = new BigIntegerParser <string>(); // As fábricas responsáveis pela instanciação de matrizes var integerSquareArrayMatrixfactory = new ArraySquareMatrixFactory <int>(); var longSquareArrayMatrixFactory = new ArraySquareMatrixFactory <long>(); var bigIntegerSquareArrayMatrixfactory = new ArraySquareMatrixFactory <BigInteger>(); // Os anéis de matrizes var integerGenericMatrixRing = new GeneralMatrixRing <int>( 2, integerSquareArrayMatrixfactory, integerDomain); var longGenericMatrixRing = new GeneralMatrixRing <long>( 2, longSquareArrayMatrixFactory, longDomain); var bigIntegerGenericMatrixRing = new GeneralMatrixRing <BigInteger>( 2, bigIntegerSquareArrayMatrixfactory, bigIntegerDomain); // Os objectos responsáveis pela conversão entre os coeficientes e o grau (inteiro) var integerMatrixConversion = new CantConvertConversion <int, IMatrix <int> >(); var longMatrixConversion = new CantConvertConversion <int, IMatrix <long> >(); var bigIntegerMatrixConversion = new CantConvertConversion <int, IMatrix <BigInteger> >(); var integerMatrixConfigParser = new ConfigMatrixParser <int, IMatrix <int> >( integerParser, 2, 2, (i, j) => integerSquareArrayMatrixfactory.CreateMatrix(i, j)); integerMatrixConfigParser.SeparatorSymbType = "comma"; integerMatrixConfigParser.MapInternalDelimiters("left_bracket", "right_bracket"); integerMatrixConfigParser.AddBlanckSymbolType("blancks"); var longMatrixConfigParser = new ConfigMatrixParser <long, IMatrix <long> >( longParser, 2, 2, (i, j) => longSquareArrayMatrixFactory.CreateMatrix(i, j)); longMatrixConfigParser.SeparatorSymbType = "comma"; longMatrixConfigParser.MapInternalDelimiters("left_bracket", "right_bracket"); longMatrixConfigParser.AddBlanckSymbolType("blancks"); var bigIntegerMatrixConfigParser = new ConfigMatrixParser <BigInteger, IMatrix <BigInteger> >( bigIntegerParser, 2, 2, (i, j) => bigIntegerSquareArrayMatrixfactory.CreateMatrix(i, j)); bigIntegerMatrixConfigParser.SeparatorSymbType = "comma"; bigIntegerMatrixConfigParser.MapInternalDelimiters("left_bracket", "right_bracket"); bigIntegerMatrixConfigParser.AddBlanckSymbolType("blancks"); // Leitura dos polinómios e subsequente teste. var integerPolynomial = TestsHelper.ReadUnivarPolynomial <IMatrix <int> >( polynomialText, integerGenericMatrixRing, integerMatrixConfigParser, integerMatrixConversion, variableName, arrayDelimiters); var integerExpectedDerivative = TestsHelper.ReadUnivarPolynomial( polynomialDerivativeText, integerGenericMatrixRing, integerMatrixConfigParser, integerMatrixConversion, variableName, arrayDelimiters, true); var integerActualDerivative = integerPolynomial.GetPolynomialDerivative(integerGenericMatrixRing); Assert.IsTrue( new UnivarPolynomNormalFormEqualityComparer <IMatrix <int> >(integerGenericMatrixRing).Equals(integerExpectedDerivative, integerActualDerivative), string.Format("Expected {0} isn't equal to actual {1}.", integerExpectedDerivative, integerActualDerivative)); var longPolynomial = TestsHelper.ReadUnivarPolynomial( polynomialText, longGenericMatrixRing, longMatrixConfigParser, longMatrixConversion, variableName, arrayDelimiters); var longExpectedDerivative = TestsHelper.ReadUnivarPolynomial( polynomialDerivativeText, longGenericMatrixRing, longMatrixConfigParser, longMatrixConversion, variableName, arrayDelimiters, true); var longActualDerivative = longPolynomial.GetPolynomialDerivative(longGenericMatrixRing); Assert.IsTrue( new UnivarPolynomNormalFormEqualityComparer <IMatrix <long> >(longGenericMatrixRing).Equals(longExpectedDerivative, longActualDerivative), string.Format("Expected {0} isn't equal to actual {1}.", integerExpectedDerivative, integerActualDerivative)); var bigIntegerPolynomial = TestsHelper.ReadUnivarPolynomial( polynomialText, bigIntegerGenericMatrixRing, bigIntegerMatrixConfigParser, bigIntegerMatrixConversion, variableName, arrayDelimiters); var bigIntegerExpectedDerivative = TestsHelper.ReadUnivarPolynomial( polynomialDerivativeText, bigIntegerGenericMatrixRing, bigIntegerMatrixConfigParser, bigIntegerMatrixConversion, variableName, arrayDelimiters, true); var bigIntegerActualDerivative = bigIntegerPolynomial.GetPolynomialDerivative(bigIntegerGenericMatrixRing); Assert.IsTrue( new UnivarPolynomNormalFormEqualityComparer <IMatrix <BigInteger> >( bigIntegerGenericMatrixRing).Equals(bigIntegerExpectedDerivative, bigIntegerActualDerivative), string.Format("Expected {0} isn't equal to actual {1}.", integerExpectedDerivative, integerActualDerivative)); }
public static Either <TLeft, long> ParseToLong <TLeft>(this string source, TLeft left) { return(LongParser.Parse(source, left)); }
internal LongComparator(int numHits, System.String field, Lucene.Net.Search.Parser parser) { values = new long[numHits]; this.field = field; this.parser = (LongParser)parser; }
public void PowerTest_IntegerPolynomial() { var integerDomain = new IntegerDomain(); var longDomain = new LongDomain(); var bigIntegerDomain = new BigIntegerDomain(); var variableName = "x"; var intPolDomain = new UnivarPolynomRing <int>(variableName, integerDomain); var longPolDomain = new UnivarPolynomRing <long>(variableName, longDomain); var bigIntegerPolDomain = new UnivarPolynomRing <BigInteger>(variableName, bigIntegerDomain); // Leitores var integerParser = new IntegerParser <string>(); var longParser = new LongParser <string>(); var bigIntegerParser = new BigIntegerParser <string>(); var integerConversion = new ElementToElementConversion <int>(); var longToIntegerConversion = new LongToIntegerConversion(); var bigIntegerToIntegerConversion = new BigIntegerToIntegerConversion(); var intPowers = new int[3] { 2, 3, 4 }; var longPowers = new long[3] { 2, 3, 4 }; var bigIntPowers = new BigInteger[3] { 2, 3, 4 }; var polynomialsTexts = new string[3] { "x^3-2*x^2+3*x-1", "2*x^2+4*x+4", "x+1" }; var expectedPolinomialsTexts = new string[3] { "x^6-4*x^5+10*x^4-14*x^3+13*x^2-6*x+1", "8*x^6+48*x^5+144*x^4+256*x^3+288*x^2+192*x+64", "x^4+4*x^3+6*x^2+4*x+1" }; // Coeficientes inteiros. for (int i = 0; i < 3; ++i) { var polynomialValue = TestsHelper.ReadUnivarPolynomial( polynomialsTexts[i], integerDomain, integerParser, integerConversion, variableName); var expectedPolynomial = TestsHelper.ReadUnivarPolynomial( expectedPolinomialsTexts[i], integerDomain, integerParser, integerConversion, variableName); var actualPolynomial = MathFunctions.Power(polynomialValue, intPowers[i], intPolDomain); Assert.AreEqual(expectedPolynomial, actualPolynomial); } // Coeficientes longos. for (int i = 0; i < 3; ++i) { var polynomialValue = TestsHelper.ReadUnivarPolynomial( polynomialsTexts[i], longDomain, longParser, longToIntegerConversion, variableName); var expectedPolynomial = TestsHelper.ReadUnivarPolynomial( expectedPolinomialsTexts[i], longDomain, longParser, longToIntegerConversion, variableName); var actualPolynomial = MathFunctions.Power(polynomialValue, intPowers[i], longPolDomain); Assert.AreEqual(expectedPolynomial, actualPolynomial); } // Coeficientes correspondentes a inteiros de precisão arbitrária. for (int i = 0; i < 3; ++i) { var polynomialValue = TestsHelper.ReadUnivarPolynomial( polynomialsTexts[i], bigIntegerDomain, bigIntegerParser, bigIntegerToIntegerConversion, variableName); var expectedPolynomial = TestsHelper.ReadUnivarPolynomial( expectedPolinomialsTexts[i], bigIntegerDomain, bigIntegerParser, bigIntegerToIntegerConversion, variableName); var actualPolynomial = MathFunctions.Power(polynomialValue, intPowers[i], bigIntegerPolDomain); Assert.AreEqual(expectedPolynomial, actualPolynomial); } }