public void GivenOneLegalDigit_WithWrongChecksum_ShouldReturnOnePrintedDigitWithErrorMarker() { var input = new Digit[] { new Digit(1) }; var result = Act_OutputFor(input); result.Should().Be("1 ERR"); }
public void GivenNoDigits_ShouldReturnEmptyString() { var input = new Digit[] { }; var result = Act_OutputFor(input); result.Should().BeEmpty(); }
public static void Main() { Digit d = new Digit(3); // implicit (no cast) conversion from Digit to byte byte b = d; }
public static void Main() { byte b = 3; Digit d = (Digit)b; //显式转换 Console.WriteLine(d.value); Console.WriteLine(); try { byte b1 = 10; Digit d1 = (Digit)b1; } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine(); Digit d2 = new Digit(3); byte b2 = d2; // 从Digit到byte的隐式(不使用强制)转换 Console.WriteLine(b2); Console.ReadLine(); }
//Initialise 'Display' with input string. public Lcd(string s) { Display = new Digit[12]; string[] segmentConditions = s.Split(); for (int i = 0; i < segmentConditions.Length; i++) Display[i] = new Digit(segmentConditions[i]); }
public void GivenIllegalDigitAlongWithProperDigits_ShouldMarkOnlyIllegalDigitWithQuestionMark_ButStillMarkWholeNumberAsIllegal() { var input = new Digit[] { new Digit(9), Arrange_IllegalDigit(), new Digit(3) }; var result = Act_OutputFor(input); result.Should().Be("9?3 ILL"); }
public void GivenIllegalDigits_ShouldReturnDigitsWithQuestionMarksAndIllegalMark() { var input = new Digit[] { Arrange_IllegalDigit() }; var result = Act_OutputFor(input); result.Should().Be("? ILL"); }
static void Main() { Digit dig = new Digit(7); //This call invokes the implicit "double" operator double num = dig; //This call invokes the implicit "Digit" operator Digit dig2 = 12; Console.WriteLine("num = {0} dig2 = {1}", num, dig2.val); }
/// <summary> /// Test for provided digit /// </summary> /// <returns>Object containing test results</returns> public TestResult Test(Digit digit) { List <float> networkOutput = network.Run(digit.DigitPixels); float max = networkOutput.Max(); int indexOfMax = networkOutput.IndexOf(max); return(new TestResult { Label = digit.Label.ToString(), ClassifiedAs = indexOfMax.ToString(), Correct = digit.Label == indexOfMax }); }
public void TestDigitAndZeroClasses() { var dig = new Digit(3); Assert.AreEqual(true, dig.isDigit()); Assert.AreEqual(3, dig.digit); var zero = new FunctionZero(); Assert.AreEqual(true, zero.isDigit()); Assert.AreEqual(0, zero.digit); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Pattern for unsigned integers. </summary> /// /// <remarks> Darrellp, 8/29/2011. </remarks> /// /// <param name="strName"> Name for the match. </param> /// /// <returns> Pattern to recognize unsigned integers. </returns> //////////////////////////////////////////////////////////////////////////////////////////////////// public static string UnsignedInteger(string strName = "") { string strSearch = Digit.RepAtLeast(1); if (strName != String.Empty) { strSearch = strSearch.Named(strName); } return(strSearch); }
public void ImplicitTest() { Digit dig = new Digit(7); double num = dig; Digit dig2 = 12; Console.WriteLine("num = {0} dig2 = {1}", num, dig2.val); }
static void Main() { Console.Write("Enter integer number: "); int n = int.Parse(Console.ReadLine()); Digit anwer = LastDigitToWord(n); Console.WriteLine(anwer); }
// implementation of interface 'ICloneable' public Object Clone() { Digit[] digits = new Digit[this.digits.Length]; for (int i = 0; i < this.digits.Length; i++) { digits[i] = (Digit)this.digits[i].Clone(); } return(new Number(digits)); }
/// <summary> /// /// </summary> /// <param name="str"></param> /// <param name="L"></param> /// <returns></returns> public static string Encode(string str, Digit L) { if (L == Digit.L16) { return(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 16)); } else { return(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower()); } }
private void ShipDestroyed() { _ship.Unplot(); _lives--; if (_lives > 0) { LifeLost(); } Digit.PlotLives(_lives); }
static void Main(string[] args) { byte g = 5; Digit t = (Digit)g; Console.WriteLine(t.GetType()); byte r = t; Console.WriteLine(r.ToString()); Console.ReadKey(); }
private void ShowProgressTestLoad(Digit digit, double done, int total) { var progress = new Progress(() => { test_progress_status_label.Text = done.ToString() + "/" + total.ToString(); test_progress_bar.Value = (int)(100 * done / total); test_digits.Add(digit); }); Invoke(progress); }
/// <summary> /// <para> /// This method can mutate the current instance and return it, or return a new instance, based on the supplied /// Lineage. /// </para> /// <para>If the current Lineage allows mutation from the specified Lineage, the instance will be MUTATED and returned.</para> /// <para>Otherwise, the method will return a NEW instance that is a member of the supplied Lineage. </para> /// </summary> private FTree <TChild> MutateOrCreate(Digit left, FTree <Digit> deep, Digit right, Lineage lineage) { if (_lineage.AllowMutation(lineage)) { return(_mutate(left, deep, right)); } else { return(new Compound(left, deep, right, lineage)); } }
void Start() { Digit dig = new Digit(7); //This call invokes the implicit "double" operator double num = dig; //This call invokes the implicit "Digit" operator Digit dig2 = 12; Debug.Log (num); Debug.Log (dig2); // Debug.Log("num = {0} dig2 = {1}", num, dig2.val); }
public Number(String s) : this() { for (int i = s.Length - 1; i >= 0; i--) { if (Char.IsDigit(s[i])) { Digit d = new Digit(s[i] - '0'); this.digits.Add(d); } } }
public SevenSegmentsDisplay(uint digitsCount = 1, bool invertSegments = false, bool invertDigits = false) { this.invertSegments = invertSegments; this.invertDigits = invertDigits; digit = new Digit(); enabledDigits = new bool[digitsCount]; sync = new object(); Reset(); }
private Digit CreateUniqueDigit() { Digit digit = digitCreator.CreateDigit(); while (!hashSet.Add(digit)) { digit = digitCreator.CreateDigit(); } return(digit); }
static Digit join(Digit current, Digit next) { current.Section0 |= next.Section0; current.Section1 |= next.Section1; current.Section2 |= next.Section2; current.Section3 |= next.Section3; current.Section4 |= next.Section4; current.Section5 |= next.Section5; current.Section6 |= next.Section6; return(current); }
public static void ReverseTheDigits(Number) { char[] CharDigit = Digit.ToCharArray(); string ReversedString = null; int a = 0; if (CharDigit[0] == '-') { a = 1; ReversedString += CharDigit[0]; } }
public static void Main() { var d = new Digit(7); byte number = d; Console.WriteLine(number); // output: 7 Digit digit = (Digit)number; Console.WriteLine(digit); // output: 7 }
// indexer private Digit this[int i] { get { Digit d = new Digit(0); if (i >= 0 && i < this.digits.Length) { d = this.digits[i]; } return(d); } }
public void TestCalc(int aValue, int bValue, int exp) { Digit a = new Digit(); a.Value = aValue; Digit b = new Digit(); b.Value = bValue; var sum = Program.Calc(a, b); Assert.Equal(exp, sum); }
// returns the first nhx hex digits of the fraction of x. static Digit[] IHex(double x, int nhx) { double y = Math.Abs(x); var list = new Digit[nhx]; for (int i = 0; i < nhx; i++) { y = 16.0 * (y - Math.Floor(y)); list[i] = new Digit((int)y, 16); } return(list); }
public Number Reverse() { List <Digit> digits = new List <Digit>(); for (int i = 0; i < this.digits.Count; i++) { Digit d = (Digit)this.digits[this.digits.Count - 1 - i].Clone(); digits.Add(d); } return(new Number(digits)); }
static void Main() { Digit a = (Digit)5; Digit b = (Digit)3; Digit plus = a + b; Digit minus = a - b; bool equals = (a == b); Console.WriteLine("{0} + {1} = {2}", a, b, plus); Console.WriteLine("{0} - {1} = {2}", a, b, minus); Console.WriteLine("{0} == {1} = {2}", a, b, equals); }
public void ImplicitOperator_Digitからbyteへ暗黙的な変換ができる() { // Arrange var src = new Digit(6); // Act // キャストは不要 byte actual = src; // Assert Assert.Equal(6, actual); }
static void Main() { try { byte b = 3; Digit d = (Digit)b; // explicit conversion } catch (Exception e) { Console.WriteLine("{0} Exception caught.", e); } }
// indexer private Digit this[int i] { get { Digit d = new Digit(0); if (i >= 0 && i < this.digits.Count) { d = (Digit)this.digits[i]; } return(d); } }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Pattern for floats. </summary> /// /// <remarks> Darrellp, 8/29/2011. </remarks> /// /// <param name="strName"> Name for the match. </param> /// /// <returns> Pattern to recognize floats. </returns> //////////////////////////////////////////////////////////////////////////////////////////////////// public static string Float(string strName = "") { string dot = '.'.Esc().Optional(); string digits = Digit.Rep(0); string strSearch = "-".Optional() + AnyOf(UnsignedInteger() + dot + digits, digits + dot + UnsignedInteger()); if (strName != String.Empty) { strSearch = strSearch.Named(strName); } return(strSearch); }
public DeepFTree(Digit <T> frontDig, FTree <Node <T> > innerFT, Digit <T> backDig) { if (frontDig.digNodes.Count > 0) { this.frontDig = frontDig; this.innerFT = innerFT; this.backDig = backDig; } else { throw new Exception("The DeepFTree() constructor is passed an empty frontDig !"); } }
/// <summary> /// Display a value on a digit /// </summary> /// <param name="digit">Digit place where value must be displayed </param> /// <param name="value">Value to display</param> public void Display(Digit digit, int value) { SendStartSignal(); WriteValue(AddrFixed); SendStopSignal(); SendStartSignal(); WriteValue(AddrStart + (int)digit); WriteValue(Digits[value] + (_bPoint ? 0x80 : 0x00)); SendStopSignal(); SendStartSignal(); WriteValue(_cmdDisplayCtrl); }
public static void Run() { Console.WriteLine("-Conversion"); var d = new Digit(7); byte number = d; Console.WriteLine(number); // output: 7 Digit digit = (Digit)number; // onli explicit conversion allowd Console.WriteLine(digit); }
/// <summary> /// Сложение целых чисел (в т.ч. отрицательных) /// </summary> /// <param name="n1">Слогаемое</param> /// <param name="n2">Слогаемое</param> /// <returns>Сумма</returns> public static Digit Run(Digit n1, Digit n2) { if (n1.Sign == n2.Sign)//Равные знаки - возвращаем сумму с тем же знаком { return(new Digit(n1.Sign, N_4.Run(n1.Value, n2.Value))); } if (N_1.Run(n1.Value, n2.Value) == 0)//Одинаковые числа и разные знаки - возвращаем 0 { return(new Digit("0")); } //Разные числа и знаки - возвращем знак большего числа и модуль разности return(new Digit((N_1.Run(n1.Value, n2.Value) == 1)? n1.Sign : n2.Sign, N_5.Run(Max(n1.Value, n2.Value), Min(n1.Value, n2.Value)))); }
public static int getDigit(int number, Digit digit) { var chars = number.ToString().ToCharArray(); if(chars.Length <= (int)digit) { return 0; } else { var pos = (chars.Length - (int)digit) - 1; var c = chars[pos]; int result = int.Parse(c.ToString()); return result; } }
// fill digit.Pixels for every digit in digits private Digit[] FillDigitPixels(Digit[] digits, byte[,] buf) { foreach (Digit digit in digits) { digit.Height = digit.Bottom - digit.Top; digit.Width = digit.Right - digit.Left; digit.Pixels = new byte[digit.Height, digit.Width]; for (int i = digit.Top; i < digit.Bottom; i++) { for (int j = digit.Left; j < digit.Right; j++) { if (buf[i, j] == 255) { digit.Pixels[i - digit.Top, j - digit.Left] = buf[i, j]; } } } } return digits; }
public Digit[] AllocateDigits(byte[,] sbuf, int height, int width) { Digit[] digits = new Digit[3]; for (int n = 0; n < 3; n++) { digits[n] = new Digit(width, 0, height, 0); } int curDigit = 0; // 0, 1, 2 bool zeroColumn; bool firstZeroColumn = false; // from top to bottom // left to right for (int j = 0; j < width; j++) // 242 { zeroColumn = true; for (int i = 0; i < height; i++) // 180 { if (sbuf[i, j] == 255) // check black pixel only { // calculating borders of digit if (j < digits[curDigit].Left) digits[curDigit].Left = j; if (j > digits[curDigit].Right) digits[curDigit].Right = j; if (i < digits[curDigit].Top) digits[curDigit].Top = i; if (i > digits[curDigit].Bottom) digits[curDigit].Bottom = i; if (zeroColumn) { zeroColumn = false; } if (!firstZeroColumn) { firstZeroColumn = true; } } } if (zeroColumn && firstZeroColumn) { curDigit++; firstZeroColumn = false; if (curDigit == 3) { goto exit; } } } exit: return FillDigitPixels(digits, sbuf); }
/// <summary> /// 时间戳转为C#格式时间 /// </summary> /// <param name=”timeStamp”></param> /// <returns></returns> public static DateTime ToCSharpDateTime(this long timeStamp, Digit digit = Digit.Thirteen) { return TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).Add(new TimeSpan(timeStamp * (int)digit)); }
private string Act_OutputFor(Digit[] digits) { var accountNumber = new AccountNumber(digits); return OutputPrinter.PrintNumberRepresentation(accountNumber); }
static DigitRecognizerRecord getRecord(Digit digit) { return new DigitRecognizerRecord {Digit = digit, Pixels = Pixels[digit]}; }
public void TestFunctionsSuccAndDbl() { var funf = new Digit(5); var succ = new FunctionSucc(); var res = succ.exec(funf); Assert.AreEqual(true, res.isDigit()); Assert.AreEqual(6, (res as Digit).digit); var dbl = new FunctionDbl(); var res2 = dbl.exec(funf); Assert.AreEqual(true, res2.isDigit()); Assert.AreEqual(10, (res2 as Digit).digit); }
public void GivenTwoLegalDigits_ShouldReturnTwoPrintedDigits() { var input = new Digit[] { new Digit(5), new Digit(1) }; var result = Act_OutputFor(input); result.Should().Be("51"); }
static void Main() { Digit d = new Digit(3); byte b = d; // implicit conversion -- no cast needed }
private void AssertScanResult(string input, int expected) { var scanner = new Digit(input); Assert.That(scanner.ToChar(), Is.EqualTo(Char.Parse(expected.ToString()))); }
public static void TypesConversion() { // Неявные implicit conversions byte b = 23; int i = b; byte b2 = (byte)i; Console.WriteLine(i); int numVal = Int32.Parse("-105"); Console.WriteLine(numVal); try { int m = Int32.Parse("abc"); } catch (FormatException e) { Console.WriteLine(e.Message); } string inputString = "abc"; int numValue; bool parsed = Int32.TryParse(inputString, out numValue); if (!parsed) Console.WriteLine("Int32.TryParse could not parse '{0}' to an int.\n", inputString); // Implicit conversion. num long can // hold any value an int can hold, and more! int num2 = 2147483647; long bigNum = num2; Digit dig = new Digit(7); //This call invokes the implicit "double" operator double num = dig; //This call invokes the implicit "Digit" operator Digit dig2 = 12; Console.WriteLine("num = {0} dig2 = {1}", num, dig2.val); }