Data Type

.We need data type to defined Column, local variable, expression, and parameters
.An attribute that specifies the type of data(integer, characters, money and so on) that the object can hold.
.User defined data type is also there.

Characters encoding fall in below two types

Non-Unicode: Uses 1 byte(8 bits) to encode each characters.
It can hold 0 – 255 different characters.

Unicode : It comes into the picture when we are storing chineese , french and etc language data.
It uses 2 bytes to encode each characters.
It can represents 65,536 characters.

You can minimize the characters conversion issues by using Unicode data types throughout your system.

SQL server supports
-nchar
-nvarchar
-ntext
It requires wider range of characters. And more space is needed to store Unicode characters.

The maxium size for nchar and nvarchar is 4000 not 8000 like char and varchar (because it takes 2 bytes to store single char).

Unicode constants are specified with a leading N: N’A Unicode string.

Below are the different categories

.Exact Numeric
.Approximate Numeric
.Characters String
.Binary

Exact Numeric: Uses integer data
-bigint -storage Size 8 bytes : -2^63 – 2^63-1
-int : 4 bytes
-smallint : 2bytes
-tinyint : 1 byte :  0-255
-Bit : 0,1, null

-Decimal and numeric:
-Decimal /Numeric:
.Fixed precision and scale numeric  : -10^38 + 1 to 10^38-1
.Precision : maximum number of decimal digits cab be stored, both to the left and right of the decimal point
.Scale : maximum number of decimal digits to the right of the decimal point/
-Monetary Data type to represent monetary or currency value:
-money : -2^63 – 2^63-1 : 8 bytes
-smallmoney : 4 bytes

Approximate Numeric:
.Approximate number data types use with floating point numeric data, not all values in the data type range can be precisely represented.
-Float : -1.79E+308 – 1.79E+308
-Real : -3.40E+38 through 3.40E38

Datetime : January 1, 1753 – December 31,9999 accuracy of one three hundredth of a second.
Smalldatetime : January 1, 1900 through June 6, 2079 with accuracy to the minute

Character String:
Fixed length char and variable length char.

-char[n] max. size 8000 storage size n bytes
-varchar[n] : max. 8000 storage size depend on data stored.
-text : variable length non-Unicode data in the code page of the server and with a max length of 2^31-1 chars.

Binary String:  This can be either fixed or variables
-binary[n] : max size is 8000, storage size is n+4 bytes.
-varbinary[n] : max size is 8000, storage size is n+4 bytes.
-image : variable length 0 through 2^31 -1 bytes

Unicode :
nchar[n] : Fixed length : 1 – 4000 size.
nvarchar[n] : variable length : 1 – 4000 size.
ntext : variable length : 2^30 -1

 

#data-type

Unit testing using nUnit tool

In computer programming, unit testing is a software testing method by which individual units of source code, sets of one or more computer program modules,  procedures developed to solve the problem, are tested to determine whether they are fit for use.

The steps involved in unit testing are:

1) Documentation

2) What should be tested while unit testing

3) Automate where Necessary

Below is the sequence of testing that has to be done while developing software

>> Unit testing

>> Integration testing

>> System testing

>> Acceptance testing

In this article we will discuss the nUnit tool to do the unit testing

NUnit is an open source unit testing framework for Microsoft .NET. It serves the same purpose as JUnit does in the Java world, and is one of many programs in the xUnit family.

To understand how it works, lets create a sample application, in below example I have created the sample class called Mathmetics with two functions “Add” and “Substraction”.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mathmetics
{
    public class Maths
    {
        public Maths() { 
        
        }

        public int Add(int number1, int number2)
        {
            return number1 + number2;        
        }

        public int Subtraction(int number1, int number2)
        {
            return number1 - number2;
        }
    }
}

In order to test the above class using the nUnit tool, let’s create another project “Window Class Library” application in our case, I have created the “MathmeticsTest” with below code.

Note*: Make sure you have downloaded the nUnit tool and added the reference of “nunit.framework.dll” in your project and also added the reference of the project contains above class.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Mathmetics;

namespace MathmeticsTest
{
    [TestFixture]
    class MathsTest
    {
        Maths maths;

        [TestFixtureSetUp]
        public void SetupTest()
        {
            maths = new Maths();
        }

        [Test]
        public void AddTest() { 
            int intResult = maths.Add(1,2);
            Assert.AreEqual(3, intResult);
        }

        [Test]
        public void SubtractionTest() {
            int intResult = maths.Subtraction(2,1);
            Assert.AreEqual(1,intResult);
        }

        [TestFixtureTearDown]
        public void TearDownTest() {
            maths = null;
        }
    }
}

Before going further let’s understand the attributes used in Unit testing with nUnit tool.

TestFixtureSetUp: SetUp is generally used for initialization purposes. Any code that must be initialized or set prior to executing a test is put in functions marked with this attribute.

TestFixtureTearDown: This is an attribute that acts the opposite of [SetUp]. It means the code written with this attribute is executed last, this is generally used for cleanup purpose.

Test: This attribute is used to test the method.

Test with ExpectedException attribute: This attribute is used to test methods that need to throw an exception in some cases. The cases may be FileNotFoundException and others.

e.g.

[Test]
[ExpectedException(typeof(MissingFileException))]

Ignore: This is the attribute which is used for the code that needs to be bypassed.

Now, compile the code written in the class library project. Then, open the bin folder of nUnit tool and execute the “nunit.exe” exe.

This will open an GUI, browse to the “MathmeticsTest.dll” created using above code.

Run the test, if everything goes fine then it will show in green color, if any test fail then it will be shown in red.

nUnit

In this example, we are using “Assert.AreEqual” method from the framework to test the result.

These are the basic steps for using the NUnit framework for unit testing.

#nunit-tool, #unit-testing