public virtual void TestOverlappedTokensLattice2() { TokenStream ts = new CannedTokenStream(new Token[] { Token("abc", 1, 1), Token("xyz", 0, 3), Token("def", 1, 1), Token("ghi", 1, 1) }); Automaton actual = (new TokenStreamToAutomaton()).ToAutomaton(ts); Automaton a1 = BasicAutomata.MakeString("xyz"); Automaton a2 = Join("abc", "def", "ghi"); Automaton expected = BasicOperations.Union(a1, a2); //toDot(actual); Assert.IsTrue(BasicOperations.SameLanguage(expected, actual)); }
public virtual void TestOverlappedTokensSausage() { // Two tokens on top of each other (sausage): TokenStream ts = new CannedTokenStream(new Token[] { Token("abc", 1, 1), Token("xyz", 0, 1) }); Automaton actual = (new TokenStreamToAutomaton()).ToAutomaton(ts); Automaton a1 = BasicAutomata.MakeString("abc"); Automaton a2 = BasicAutomata.MakeString("xyz"); Automaton expected = BasicOperations.Union(a1, a2); Assert.IsTrue(BasicOperations.SameLanguage(expected, actual)); }
public void Add_AddTwoIntegers_ResultIsCorrect(int firstNumber, int secondNumber, int expected) { //Arrange BasicOperations basicOperations = new BasicOperations(); //Act var result = basicOperations.Add(firstNumber, secondNumber); //Assert Assert.Equal(expected, result); }
public void Add_TwoPositiveNumbers_ResultIsEqualToSumOfNumbers(int firstNumber, int secondNumber, int sum) { //Arrange BasicOperations sut = new BasicOperations(); //Act int result = sut.Add(firstNumber, secondNumber); //Assert Assert.Equal(sum, result); }
private Automaton Join(params string[] strings) { IList <Automaton> @as = new List <Automaton>(); foreach (string s in strings) { @as.Add(BasicAutomata.MakeString(s)); @as.Add(SEP_A); } @as.RemoveAt(@as.Count - 1); return(BasicOperations.Concatenate(@as)); }
public override List <string> SplitTasks(List <string> rawData, List <int> taskSplits) { var taskList = new List <string>(); var tasklength = BasicOperations.TaskLength(taskSplits, rawData.Count); for (int split = 0; split < taskSplits.Count; split++) { string taskString = BasicOperations.Task2String(rawData, tasklength, taskSplits[split]); taskList.Add(taskString); } return(taskList); }
public void TaskLengthTest() { var expected = 4; //act var actual = BasicOperations.TaskLength(TaskSplits, InputList.Count); //assert Assert.AreEqual(expected, actual); }
public virtual void TestRewritePrefix() { Automaton pfx = BasicAutomata.MakeString("do"); pfx.ExpandSingleton(); // expand singleton representation for testing Automaton prefixAutomaton = BasicOperations.Concatenate(pfx, BasicAutomata.MakeAnyString()); AutomatonQuery aq = new AutomatonQuery(NewTerm("bogus"), prefixAutomaton); Terms terms = MultiFields.GetTerms(Searcher.IndexReader, FN); Assert.IsTrue(aq.GetTermsEnum(terms) is PrefixTermsEnum); Assert.AreEqual(3, AutomatonQueryNrHits(aq)); }
public void AddTest() { BasicOperations target = new BasicOperations(); // TODO: Initialize to an appropriate value int numberA = 0; // TODO: Initialize to an appropriate value int numberB = 0; // TODO: Initialize to an appropriate value int expected = 0; // TODO: Initialize to an appropriate value int actual; actual = target.Add(numberA, numberB); Assert.AreEqual(expected, actual); //Assert.Inconclusive("Verify the correctness of this test method."); }
public void Task2StringTest() { //arrange string expected = "<Name>Task Number</Name>\ntest task\ntest task\ntest task"; var taskLength = 4; //act var actual = BasicOperations.Task2String(InputList, taskLength, TaskSplits[0]); //assert Assert.AreEqual(actual, expected); }
protected internal override Automaton ConvertAutomaton(Automaton a) { if (unicodeAware) { Automaton utf8automaton = (new UTF32ToUTF8()).Convert(a); BasicOperations.Determinize(utf8automaton); return(utf8automaton); } else { return(a); } }
public void Add_AddPositiveNumbersUsingAAA_ResultIsCorrect() { //Arrange var basicOperations = new BasicOperations(); //Act var result = basicOperations.Add(5, 1); //Assert var expectedResult = 6; Assert.AreEqual(result, expectedResult); }
public void MinusFunktionTest0() { //Arrange var cal = new BasicOperations(2, 2); //Act double result = cal.MinusFunktion(); //Assert Assert.AreEqual(0, result); }
public void Add_AddNegativeNumbers_ResultIsCorrect() { //Lets try to use debug mode here //Arrange var basicOperations = new BasicOperations(); //Act var result = basicOperations.Add(-5, -1); //Assert var expectedResult = -6; Assert.AreEqual(result, expectedResult); }
public void DividerFunktionTest2() { //Arrange var cal = new BasicOperations(4, 2); //Act double result = cal.DividerFunktion(); //Assert Assert.AreEqual(2, result); }
public void TestKeep() { CharacterRunAutomaton keepWords = new CharacterRunAutomaton( BasicOperations.Complement( BasicOperations.Union( BasicAutomata.MakeString("foo"), BasicAutomata.MakeString("bar")) /*, * Operations.DEFAULT_MAX_DETERMINIZED_STATES*/)); Analyzer a = new MockAnalyzer(Random, MockTokenizer.SIMPLE, true, keepWords); AssertAnalyzesTo(a, "quick foo brown bar bar fox foo", new String[] { "foo", "bar", "bar", "foo" }, new int[] { 2, 2, 1, 2 }); }
public void GangeFunktionTest10() { //Arrange var cal = new BasicOperations(2, 5); //Act double result = cal.GangeFunktion(); //Assert Assert.AreEqual(10, result); }
public virtual void TestBasicAutomata() { AssertAutomatonHits(0, BasicAutomata.MakeEmpty()); AssertAutomatonHits(0, BasicAutomata.MakeEmptyString()); AssertAutomatonHits(2, BasicAutomata.MakeAnyChar()); AssertAutomatonHits(3, BasicAutomata.MakeAnyString()); AssertAutomatonHits(2, BasicAutomata.MakeString("doc")); AssertAutomatonHits(1, BasicAutomata.MakeChar('a')); AssertAutomatonHits(2, BasicAutomata.MakeCharRange('a', 'b')); AssertAutomatonHits(2, BasicAutomata.MakeInterval(1233, 2346, 0)); AssertAutomatonHits(1, BasicAutomata.MakeInterval(0, 2000, 0)); AssertAutomatonHits(2, BasicOperations.Union(BasicAutomata.MakeChar('a'), BasicAutomata.MakeChar('b'))); AssertAutomatonHits(0, BasicOperations.Intersection(BasicAutomata.MakeChar('a'), BasicAutomata.MakeChar('b'))); AssertAutomatonHits(1, BasicOperations.Minus(BasicAutomata.MakeCharRange('a', 'b'), BasicAutomata.MakeChar('a'))); }
public void DoBasicOperation(BasicOperations opr) { if (_answerObtained) { _answerObtained = false; } if (OutputDisplay.Text != "") { string symbol = EvaluateOperation(opr); _results = double.Parse(OutputDisplay.Text); OutputDisplay.Text = ""; InputDisplay.Text = _results.ToString() + " " + symbol; } }
public void MoveToMemoryList(BasicOperations function, IndexBaseAddresses fromValue, IndexBaseAddresses toValue, TextBox[] textBoxes) { var disp = DispTextBox.Text; switch (function) { case BasicOperations.MOV: textBoxes[1].Text = textBoxes[0].Text; if (fromValue == IndexBaseAddresses.DIplusBP || fromValue == IndexBaseAddresses.SIplusBP || fromValue == IndexBaseAddresses.DIplusBX || fromValue == IndexBaseAddresses.SIplusBX) { MemoryCells.Add(new MemoryCell { Data = textBoxes[0].Text, EffectiveAddress = $"{textBoxes[0].Text}{disp}" }); } else { MemoryCells.Add(new MemoryCell { Data = textBoxes[1].Text, EffectiveAddress = $"{textBoxes[1].Text}{disp}" }); } break; case BasicOperations.ECHG: var toText = textBoxes[1].Text; textBoxes[1].Text = textBoxes[0].Text; textBoxes[0].Text = toText; if (fromValue == IndexBaseAddresses.DIplusBP || fromValue == IndexBaseAddresses.SIplusBP || fromValue == IndexBaseAddresses.DIplusBX || fromValue == IndexBaseAddresses.SIplusBX) { MemoryCells.Add(new MemoryCell { Data = textBoxes[0].Text, EffectiveAddress = $"{textBoxes[0].Text}{disp}" }); } else { MemoryCells.Add(new MemoryCell { Data = textBoxes[1].Text, EffectiveAddress = $"{textBoxes[1].Text}{disp}" }); } break; default: throw new ArgumentOutOfRangeException(); } }
private void Awake() { basicOperations = new BasicOperations(); operation = Operations.Addition; transform.Find("FirstFactor").Find("InputField").GetComponent <InputField>().onEndEdit.AddListener(SetFirstFactor); transform.Find("SecondFactor").Find("InputField").GetComponent <InputField>().onEndEdit.AddListener(SetSecondFactor); transform.Find("OperationDropdown").GetComponent <Dropdown>().onValueChanged.AddListener(SetOperation); transform.Find("ComputeButton").GetComponent <Button>().onClick.AddListener(() => { float result = 0; switch (operation) { case Operations.Addition: result = basicOperations.Addition(firstFactor, secondFactor); break; case Operations.Subtraction: result = basicOperations.Subtraction(firstFactor, secondFactor); break; case Operations.Multiplication: result = basicOperations.Multiplication(firstFactor, secondFactor); break; case Operations.Division: if (secondFactor == 0) { ShowResultMessage("You can't divide by 0!"); return; } result = basicOperations.Division(firstFactor, secondFactor); break; } ShowResult(result); }); resultText = transform.Find("Result").Find("Value").GetComponent <Text>(); }
public static BasicOperations GetReverse(this BasicOperations op) { switch (op) { case BasicOperations.Add: return(BasicOperations.Sub); case BasicOperations.Sub: return(BasicOperations.Add); case BasicOperations.Xor: return(BasicOperations.Xor); default: throw new InvalidOperationException(string.Format("Cannot reverse unknown op '{0}'", op)); } }
private static void Main(string[] args) { var tester = new Assert("Basic Operations"); var basicOperations = new BasicOperations(); tester.AreEqual("Addition", 10, basicOperations.Addition(5, 5)); tester.AreEqual("Subtraction", 0, basicOperations.Subtraction(5, 5)); tester.AreEqual("Division", 1, basicOperations.Division(5, 5)); tester.ThrowsException <ZeroDivisorNotAllowed>("Zero Division", () => basicOperations.Division(10, 0)); tester.AreEqual("Multiplication", 25, basicOperations.Multiplication(5, 5)); Console.ReadKey(); }
public virtual void TestIntersect() { for (int i = 0; i < numIterations; i++) { string reg = AutomatonTestUtil.RandomRegexp(Random); Automaton automaton = (new RegExp(reg, RegExpSyntax.NONE)).ToAutomaton(); CompiledAutomaton ca = new CompiledAutomaton(automaton, SpecialOperations.IsFinite(automaton), false); TermsEnum te = MultiFields.GetTerms(reader, "field").Intersect(ca, null); Automaton expected = BasicOperations.Intersection(termsAutomaton, automaton); JCG.SortedSet <BytesRef> found = new JCG.SortedSet <BytesRef>(); while (te.Next() != null) { found.Add(BytesRef.DeepCopyOf(te.Term)); } Automaton actual = BasicAutomata.MakeStringUnion(found); Assert.IsTrue(BasicOperations.SameLanguage(expected, actual)); } }
/// <summary> /// Convert Lucene wildcard syntax into an automaton. /// <para/> /// @lucene.internal /// </summary> public static Automaton ToAutomaton(Term wildcardquery) { IList <Automaton> automata = new JCG.List <Automaton>(); string wildcardText = wildcardquery.Text; for (int i = 0; i < wildcardText.Length;) { int c = Character.CodePointAt(wildcardText, i); int length = Character.CharCount(c); switch (c) { case WILDCARD_STRING: automata.Add(BasicAutomata.MakeAnyString()); break; case WILDCARD_CHAR: automata.Add(BasicAutomata.MakeAnyChar()); break; case WILDCARD_ESCAPE: // add the next codepoint instead, if it exists if (i + length < wildcardText.Length) { int nextChar = Character.CodePointAt(wildcardText, i + length); length += Character.CharCount(nextChar); automata.Add(BasicAutomata.MakeChar(nextChar)); break; } // else fallthru, lenient parsing with a trailing \ goto default; default: automata.Add(BasicAutomata.MakeChar(c)); break; } i += length; } return(BasicOperations.Concatenate(automata)); }
static void Main(string[] args) { Console.WriteLine("-------------- Velkommen til din nye lommeregner --------------"); Console.WriteLine("Indtast dit første tal..."); string Tal1 = Console.ReadLine(); double temp1 = Double.Parse(Tal1); Console.WriteLine("Indtast en operator..."); string Operator = Console.ReadLine(); Console.WriteLine("Indtast dit andet tal..."); string Tal2 = Console.ReadLine(); double temp2 = Double.Parse(Tal2); var calc = new BasicOperations(temp1, temp2); switch (Operator) { case "+": Console.WriteLine(calc.PlusFunktion()); break; case "-": Console.WriteLine(calc.MinusFunktion()); break; case "*": Console.WriteLine(calc.GangeFunktion()); break; case "/": Console.WriteLine(calc.DividerFunktion()); break; default: Console.WriteLine("Indtast venligst en korrekt operator."); break; } }
public override void SetUp() { base.SetUp(); // build an automaton matching this jvm's letter definition State initial = new State(); State accept = new State(); accept.Accept = true; for (int i = 0; i <= 0x10FFFF; i++) { if (Character.IsLetter(i)) { initial.AddTransition(new Transition(i, i, accept)); } } Automaton single = new Automaton(initial); single.Reduce(); Automaton repeat = BasicOperations.Repeat(single); jvmLetter = new CharacterRunAutomaton(repeat); }
public static Op GetOpFunc(this BasicOperations op) { Op d = null; switch (op) { case BasicOperations.Add: d = (a, b) => a + b; break; case BasicOperations.Sub: d = (a, b) => a - b; break; case BasicOperations.Xor: d = (a, b) => a ^ b; break; default: throw new ArgumentOutOfRangeException(nameof(op)); } return(d); }
public virtual void TestFiniteVersusInfinite() { for (int i = 0; i < numIterations; i++) { string reg = AutomatonTestUtil.RandomRegexp(Random); Automaton automaton = (new RegExp(reg, RegExpSyntax.NONE)).ToAutomaton(); IList <BytesRef> matchedTerms = new List <BytesRef>(); foreach (BytesRef t in terms) { if (BasicOperations.Run(automaton, t.Utf8ToString())) { matchedTerms.Add(t); } } Automaton alternate = BasicAutomata.MakeStringUnion(matchedTerms); //System.out.println("match " + matchedTerms.Size() + " " + alternate.getNumberOfStates() + " states, sigma=" + alternate.getStartPoints().length); //AutomatonTestUtil.minimizeSimple(alternate); //System.out.println("minmize done"); AutomatonQuery a1 = new AutomatonQuery(new Term("field", ""), automaton); AutomatonQuery a2 = new AutomatonQuery(new Term("field", ""), alternate); CheckHits.CheckEqual(a1, searcher.Search(a1, 25).ScoreDocs, searcher.Search(a2, 25).ScoreDocs); } }
/// <summary> /// Initialize levenshtein DFAs up to maxDistance, if possible </summary> private IList <CompiledAutomaton> InitAutomata(int maxDistance) { IList <CompiledAutomaton> runAutomata = dfaAtt.Automata; //System.out.println("cached automata size: " + runAutomata.size()); if (runAutomata.Count <= maxDistance && maxDistance <= LevenshteinAutomata.MAXIMUM_SUPPORTED_DISTANCE) { LevenshteinAutomata builder = new LevenshteinAutomata(UnicodeUtil.NewString(m_termText, m_realPrefixLength, m_termText.Length - m_realPrefixLength), transpositions); for (int i = runAutomata.Count; i <= maxDistance; i++) { Automaton a = builder.ToAutomaton(i); //System.out.println("compute automaton n=" + i); // constant prefix if (m_realPrefixLength > 0) { Automaton prefix = BasicAutomata.MakeString(UnicodeUtil.NewString(m_termText, 0, m_realPrefixLength)); a = BasicOperations.Concatenate(prefix, a); } runAutomata.Add(new CompiledAutomaton(a, true, false)); } } return(runAutomata); }