private string j(Gram v) { switch(v) { case Gram.SYOU: return "小ラーメン"; case Gram.DAI: return "大ラーメン"; case Gram.DEFAULT: return "ラーメン"; default: return "指定なし"; } }
public Gram Edit(Gram gram, int id) { var gramToUpdate = grams.First(x => x.Id == id); if (gramToUpdate != null) { grams.Remove(gramToUpdate); gram.Id = id; grams.Add(gram); return(gram); } return(null); }
public void TestMethod1() { Gram G = new Gram(1); Ounces O = new Ounces(1); Converter Converter = new Converter(); double gramToOunces = 0.0352739619; double ouncesToGram = 28.3495231; Assert.AreEqual(gramToOunces, Converter.ConvertToOunces(G)); Assert.AreEqual(ouncesToGram, Converter.ConvertToGram(O)); }
public void Clear() { if (this._buffered != null) { this._buffered.Release(); this._buffered = null; } while (this._pending.Count > 0) { this._pending.Dequeue().Release(); } }
public void GramConstructorTest() { Gram target = new Gram(); Assert.AreEqual("kg", target.Symbol); Assert.AreEqual(typeof(Mass <>), target.QuantityType); Assert.AreEqual(MetricPrefix.Kilo, target.UnitPrefix); Assert.AreEqual(true, target.IsBaseUnit); Assert.AreEqual(true, target.IsDefaultUnit); }
public System.Collections.Generic.IEnumerable <Gram> All() { for (int i = 0; i < nodes.Length; i++) { Gram g = nodes[i]; while (g != null) { yield return(g); g = g.Prev; } } }
public void Clear() { if (_buffered != null) { _buffered.Release(); _buffered = null; } while (_pending.Count > 0) { _pending.Dequeue().Release(); } }
public Gram CheckFlushReady() { Gram gram = null; if (this._pending.Count == 0 && this._buffered != null) { gram = this._buffered; this._pending.Enqueue(this._buffered); this._buffered = null; } return(gram); }
public Gram Dequeue() { Gram gram = null; if (this._pending.Count > 0) { this._pending.Dequeue().Release(); if (this._pending.Count > 0) { gram = this._pending.Peek(); } } return(gram); }
public List <Gram> GetTwoThreeGrams(List <DirectoryFileInfo> files, List <DirectoryFolderInfo> folders, string catName, bool isTest) { List <Gram> result = new List <Gram>(); try { foreach (var file in files) { for (int i = 0; i < file.Content.Length - 3; i++) { file.Content = file.Content.Replace(" ", "_").Replace(Environment.NewLine, " "); if (result.Where(x => x.Content == file.Content.Substring(i, 3)).FirstOrDefault() == null) { Gram g = new Gram(); g.Content = file.Content.Substring(i, 3); g.Category = file.Category; g.FileName = file.Name; g.FileContent = file.Content; g.Type = 3; g.IsTest = isTest; g.Frequency = file.Content.Length - file.Content.Replace(g.Content, "").Length; //result.Add(g); if (isTest) { result.Add(g); } else { Gram hasGramInResult = result.Where(x => x.Content == g.Content).FirstOrDefault(); if (g.Frequency > 50 && hasGramInResult == null) { result.Add(g); } else if (hasGramInResult != null) { hasGramInResult.Frequency += g.Frequency; result.Add(hasGramInResult); } } } } } return(result); } catch (Exception e) { Console.WriteLine("HATA ! : " + e.Message); return(result); } }
public Gram CheckFlushReady() { Gram gram = null; if (_pending.Count == 0 && _buffered != null) { gram = _buffered; _pending.Enqueue(_buffered); _buffered = null; } return gram; }
public Gram[] List() { Gram[] list = new Gram[Count]; int id = 0; for (int i = 0; i < nodes.Length; i++) { Gram g = nodes[i]; while (g != null) { list[id++] = g; g = g.Prev; } } return(list); }
public Gram CheckFlushReady() { Gram gram = null; if (_pending.Count == 0 && _buffered != null) { gram = _buffered; _pending.Enqueue(_buffered); _buffered = null; } return(gram); }
private void Ok_Button_Click(object sender, RoutedEventArgs e) { IngredientName = this.Name.Text; float stock; float price; if (float.TryParse(this.Stock.Text, out stock)) { IngredientStock = stock; } else { MessageBox.Show(dataNotFloat); } if (float.TryParse(this.Stock.Text, out price)) { IngredientPrice = price; } else { MessageBox.Show(dataNotFloat); } AUnit unit; if (IngredientUnit.Equals("g")) { unit = new Gram(stock, Gram.Units.None); } else if (IngredientUnit.Equals("kg")) { unit = new Gram(stock, Gram.Units.Killo); } else if (IngredientUnit.EndsWith("L")) { // 구현 필요 임시 코드 unit = new Gram(stock, Gram.Units.Milli); } else { unit = new Gram(stock, Gram.Units.Milli); } Ingredient ingredient = new Ingredient(IngredientName, unit); ingredient.Price = IngredientPrice; ingredient.AllergyList = _allergyList; _ingredientManager.InsertIngredient(ingredient); }
/// <summary> /// Save/Create /// </summary> /// <param name="gram"></param> /// <returns></returns> public async Task SaveAsync(Gram gram) { //checks to see if we need to create a gram if (await _context.Gram.FirstOrDefaultAsync(m => m.ID == gram.ID) == null) { _context.Gram.Add(gram); } else { //Updated DB with new Gram _context.Gram.Update(gram); } //Saves to DB await _context.SaveChangesAsync(); }
static void Main(string[] args) { // Kilogram 타입 사용 예제 Kilogram kg1 = new Kilogram(5); Kilogram kg2 = new Kilogram(10); Gram gram1 = (Gram)kg1; Gram gram2 = (Gram)kg2; Kilogram kg3 = kg1 + kg2; Gram gram3 = gram1 + gram2; Console.WriteLine(gram1); Console.WriteLine(kg3); Console.WriteLine(gram3); }
public void SetWord_SetWord_String() { //Arrange string word = "cracker"; Gram newGram = new Gram(word); //Act string updatedWord = "biscuit"; newGram.SetWord(updatedWord); string result = newGram.GetWord(); //Assert Assert.AreEqual(updatedWord, result); }
public Gram Enqueue(byte[] buffer, int offset, int length) { if (buffer == null) { throw new ArgumentNullException(nameof(buffer)); } else if (!(offset >= 0 && offset < buffer.Length)) { throw new ArgumentOutOfRangeException(nameof(offset), offset, "Offset must be greater than or equal to zero and less than the size of the buffer."); } else if (length < 0 || length > buffer.Length) { throw new ArgumentOutOfRangeException(nameof(length), length, "Length cannot be less than zero or greater than the size of the buffer."); } else if ((buffer.Length - offset) < length) { throw new ArgumentException("Offset and length do not point to a valid segment within the buffer."); } int existingBytes = (_pending.Count * _CoalesceBufferSize) + (_buffered == null ? 0 : _buffered.Length); if ((existingBytes + length) > PendingCap) { throw new CapacityExceededException(); } Gram gram = null; while (length > 0) { if (_buffered == null) // nothing yet buffered { _buffered = Gram.Acquire(); } int bytesWritten = _buffered.Write(buffer, offset, length); offset += bytesWritten; length -= bytesWritten; if (_buffered.IsFull) { if (_pending.Count == 0) { gram = _buffered; } _pending.Enqueue(_buffered); _buffered = null; } } return(gram); }
public void AddWord_AddWordtoWordList_ItemList() { //Arrange string word = "dough"; Gram newGram = new Gram("hug"); List <string> newList = new List <string> { word }; //Act newGram.AddWord(word); List <string> result = newGram.GetWordList(); //Assert CollectionAssert.AreEqual(newList, result); }
public static Gram Acquire() { lock ( _pool ) { Gram gram; if ( _pool.Count > 0 ) { gram = _pool.Pop(); } else { gram = new Gram(); } gram._buffer = AcquireBuffer(); gram._length = 0; return gram; } }
public Gram Enqueue(byte[] buffer, int offset, int length) { if (buffer == null) { throw new ArgumentNullException("buffer"); } if ((offset < 0) || (offset >= buffer.Length)) { throw new ArgumentOutOfRangeException("offset", offset, "Offset must be greater than or equal to zero and less than the size of the buffer."); } if ((length < 0) || (length > buffer.Length)) { throw new ArgumentOutOfRangeException("length", length, "Length cannot be less than zero or greater than the size of the buffer."); } if ((buffer.Length - offset) < length) { throw new ArgumentException("Offset and length do not point to a valid segment within the buffer."); } int num = this.getpendingCount() + ((this._buffered == null) ? 0 : this._buffered.Length); if ((num + length) > 0x177000) { throw new CapacityExceededException(); } Gram gram = null; while (length > 0) { if (this._buffered == null) { this._buffered = Gram.Acquire(); } int num2 = this._buffered.Write(buffer, offset, length); offset += num2; length -= num2; if (this._buffered.IsFull) { if (this._pending.Count == 0) { gram = this._buffered; } this._pending.Enqueue(this._buffered); this._buffered = null; } } return(gram); }
/// <summary> /// 清理 /// </summary> public void Clear() { if (_buffered != null) { _buffered.Release(); _buffered = null; } while (_pending.Count > 0) { //_pending.Dequeue().Release(); Gram gram = null; if (_pending.TryDequeue(out gram)) { gram.Release(); } } }
public void BasicMathTests() { var fiveGrams = new Gram(5); var tenGrams = fiveGrams * 2; Assert.AreEqual(tenGrams.Value, 10); var sevenGrams = new Gram(7); var twelveGrams = fiveGrams + sevenGrams; Assert.AreEqual(twelveGrams.Value, 12); Assert.IsTrue(twelveGrams.Unit.GetType() == fiveGrams.Unit.GetType()); Assert.IsTrue(sevenGrams.Equals(twelveGrams - 5)); var twoKilograms = new Kilogram(2); var result = twoKilograms + ((twelveGrams * 3) + 4); Assert.AreEqual(result.Value, 2.04); Assert.IsTrue(Math.Abs(result.ConversionFactor - twoKilograms.ConversionFactor) < Constants.Epsilon); Console.WriteLine(result); }
public Gram Get(string key) { if (key == null || key.Length == 0) { return(null); } int h = GetHashCode(key); Gram g = nodes[h % nodes.Length]; while (g != null) { if (g.HashCode == h && Gram.Compare(g.Key, key) == 0) { break; } g = g.Prev; } return(g); }
public static void Main() { Console.WriteLine("Enter a word to compare to a list of words to anagramafy"); Gram newGram = new Gram(Console.ReadLine()); bool listMaking = true; List <string> listArray = new List <string> { }; List <string> matches = new List <string> { }; while (listMaking) { Console.WriteLine("What word would you like to compare to your primary word"); string userEnters = Console.ReadLine(); listArray.Add(userEnters); Console.WriteLine("Do you want to enter another word? '1' for yes"); if (Console.ReadLine() != "1") { listMaking = false; } } for (int i = 0; i < listArray.Count; i++) { char[] toSort = listArray[i].ToCharArray(); Array.Sort(toSort); string sorted = string.Join("", toSort); if (sorted == newGram.SortWord()) { matches.Add(listArray[i]); } } Console.WriteLine("Here are the anagrams of your word:"); Console.WriteLine("-----------------------------------"); foreach (String gramcracker in matches) { Console.WriteLine(gramcracker); } Console.WriteLine("LIIIIL BIIIIISSCUIT"); }
public void Learn(List <IState> states) { int numStates = states.Count; int maxGramState = numStates - 1 - n; for (int iState = 0; iState < maxGramState; iState++) { Gram gramStates = new Gram(n, states.GetRange(iState, n)); if (grams.ContainsKey(gramStates.uid) == false) { grams.Add(gramStates.uid, gramStates); } if (iState < maxGramState - n) { gramStates.AddLink(new Gram(n, states.GetRange(iState + n, n))); } } }
public void PathFromDefaultUnitTest() { MetricUnit target = new Gram(); target.UnitPrefix = MetricPrefix.Milli; UnitPathStack actual = target.PathFromDefaultUnit(); double expected = System.Math.Pow(10, 6); Assert.AreEqual(expected, actual.ConversionFactor); target = new Metre(); target.UnitPrefix = MetricPrefix.Tera; actual = target.PathFromDefaultUnit(); expected = System.Math.Pow(10, -12); Assert.AreEqual(expected, actual.ConversionFactor); }
public void Should_compare_with_bigger_value(double baseValue, double biggerValue) { var baseInstance = new Gram(baseValue); var biggerInstance = new Gram(biggerValue); Assert.IsFalse(baseInstance.Equals(biggerInstance), "Equals"); Assert.IsFalse(baseInstance.Equals((object)biggerInstance), "Equals object"); Assert.IsFalse(baseInstance == biggerInstance, "=="); Assert.IsTrue(baseInstance != biggerInstance, "!="); Assert.AreEqual(-1, baseInstance.CompareTo(biggerInstance), "CompareTo"); Assert.AreEqual(-1, baseInstance.CompareTo((object)biggerInstance), "CompareTo object"); Assert.IsTrue(baseInstance < biggerInstance, "<"); Assert.IsFalse(baseInstance > biggerInstance, ">"); Assert.IsTrue(baseInstance <= biggerInstance, "<="); Assert.IsFalse(baseInstance >= biggerInstance, ">="); }
public void Should_compare_with_same_value(double value) { var baseInstance = new Gram(value); var otherInstance = new Gram(value); Assert.IsTrue(baseInstance.Equals(otherInstance), "Equals"); Assert.IsTrue(baseInstance.Equals((object)otherInstance), "Equals object"); Assert.IsTrue(baseInstance == otherInstance, "=="); Assert.IsFalse(baseInstance != otherInstance, "!="); Assert.AreEqual(0, baseInstance.CompareTo(otherInstance), "CompareTo"); Assert.AreEqual(0, baseInstance.CompareTo((object)otherInstance), "CompareTo object"); Assert.IsFalse(baseInstance < otherInstance, "<"); Assert.IsFalse(baseInstance > otherInstance, ">"); Assert.IsTrue(baseInstance <= otherInstance, "<="); Assert.IsTrue(baseInstance >= otherInstance, ">="); }
public void Should_compare_with_smaller_value(double baseValue, double smallerValue) { var baseInstance = new Gram(baseValue); var smallerInstance = new Gram(smallerValue); Assert.IsFalse(baseInstance.Equals(smallerInstance), "Equals"); Assert.IsFalse(baseInstance.Equals((object)smallerInstance), "Equals object"); Assert.IsFalse(baseInstance == smallerInstance, "=="); Assert.IsTrue(baseInstance != smallerInstance, "!="); Assert.AreEqual(+1, baseInstance.CompareTo(smallerInstance), "CompareTo"); Assert.AreEqual(+1, baseInstance.CompareTo((object)smallerInstance), "CompareTo object"); Assert.IsFalse(baseInstance < smallerInstance, "<"); Assert.IsTrue(baseInstance > smallerInstance, ">"); Assert.IsFalse(baseInstance <= smallerInstance, "<="); Assert.IsTrue(baseInstance >= smallerInstance, ">="); }
public static Gram Acquire() { lock (_Pool) { Gram gram; if (_Pool.Count > 0) { gram = _Pool.Pop(); } else { gram = new Gram(); } gram.Buffer = AcquireBuffer(); gram.Length = 0; return(gram); } }
/// <summary> /// 取出要发送的数据 /// </summary> /// <returns></returns> public Gram Dequeue() { Gram gram = null; if (_pending.Count > 0) { //_pending.Dequeue().Release(); if (_pending.TryDequeue(out gram)) { gram.Release();//???why } gram = null; if (_pending.Count > 0) { //gram = _pending.Peek(); _pending.TryPeek(out gram); } } return(gram); }
public void PathToUnitTest() { double expected = 63360; Mile mil = new Mile(); Inch i = new Inch(); UnitPathStack actual = mil.PathToUnit(i); Assert.AreEqual(expected, actual.ConversionFactor); Gram g = new Gram(); g.UnitPrefix = MetricPrefix.None; Gram Mg = new Gram(); Mg.UnitPrefix = MetricPrefix.Mega; actual = g.PathToUnit(Mg); Assert.AreEqual(1e-6, actual.ConversionFactor); Metre mr = new Metre(); actual = i.PathToUnit(mr); Assert.AreEqual(0.0254, actual.ConversionFactor); //now the idea is to make any combination of units to go to any combination of units QuantityDimension qd = QuantityDimension.ParseMLT("M1L0T-1"); Unit u = Unit.DiscoverUnit(qd); Assert.AreEqual("<kg/s>", u.Symbol); Assert.AreEqual(qd, u.UnitDimension); }
public Gram Enqueue(byte[] buffer, int offset, int length) { if (buffer == null) { throw new ArgumentNullException("buffer"); } else if (!(offset >= 0 && offset < buffer.Length)) { throw new ArgumentOutOfRangeException("offset", offset, "Offset must be greater than or equal to zero and less than the size of the buffer."); } else if (length < 0 || length > buffer.Length) { throw new ArgumentOutOfRangeException("length", length, "Length cannot be less than zero or greater than the size of the buffer."); } else if ((buffer.Length - offset) < length) { throw new ArgumentException("Offset and length do not point to a valid segment within the buffer."); } int existingBytes = (_pending.Count * s_CoalesceBufferSize) + (_buffered == null ? 0 : _buffered.Length); if ((existingBytes + length) > PendingCap) { throw new CapacityExceededException(); } Gram gram = null; while (length > 0) { if (_buffered == null) { // nothing yet buffered _buffered = Gram.Acquire(); } int bytesWritten = _buffered.Write(buffer, offset, length); offset += bytesWritten; length -= bytesWritten; if (_buffered.IsFull) { if (_pending.Count == 0) { gram = _buffered; } _pending.Enqueue(_buffered); _buffered = null; } } return gram; }
public Noodle cooking(Gram g) { Noodle ret=new Noodle(); ret.NoodleVolume=g; return ret; }
public Gram CheckFlushReady() { Gram gram = _buffered; _pending.Enqueue(_buffered); _buffered = null; return gram; }
public Gram CheckFlushReady() { Gram gram = null; if (this._pending.Count == 0 && this._buffered != null) { gram = this._buffered; this._pending.Enqueue(this._buffered); this._buffered = null; } return gram; }