secerka secerovic

secerka secerovic

  • NA
  • 12
  • 11.8k

Help with NUunit test

Jul 22 2011 4:55 AM
Hello everyone!

Because I'm begginer I realized along with writing code I need to write tests.
So I started to learn Nunit tests.
Now I'm trayng to write test for this specific cod.
Unfortunately I couldn't do it. :(
I would ask you if you can help me with writing tests for this kod.
I need fo find Bob B with assert in frst test with this certain parameters(skill and skillLevel)
and in another test I need to find more people, maybe two or three people with this parameters.

How to check whether these are people who I'm searching for?


using System;
using System.Collections.Generic;

class Candidate
{
public string Name { get; set; }
public List<Skill> Skills { get; private set;}

public Candidate(string name, List<Skill> skills)
{
Name = name;
Skills = skills;
}
}

public class Skill
{
public string Name { get;set; }
public int Level { get;set; }

public Skill(string name, int level)
{
this.Name = name;
this.Level = level;
}
}

interface ICandidateSearch //interface for search
{
List<Candidate> Find(List<String> skills);
List<Candidate> Find(List<Skill> skills);
}

class CandidateSearch : ICandidateSearch
{
List<Candidate> candidates;

public List<Candidate> Find(List<String> skills)
{
List<Candidate> results = new List<Candidate>();
foreach(Candidate c in candidates)
{
bool match = true;

foreach(string name in skills)
{
bool found = false;

foreach(Skill cs in c.Skills)
{
if(name == cs.Name)
{
found = true;
break;
}
}

if (!found)
{
match = false;
break;
}
}

if (match) results.Add(c);
}

return results;
}


public List<Candidate> Find(List<Skill> skills)
{
List<Candidate> results = new List<Candidate>();

foreach(Candidate c in candidates)
{
bool match = true;

foreach(Skill s in skills)
{
bool found = false;

foreach(Skill cs in c.Skills)
{
if(s.Name == cs.Name && s.Level<= cs.Level)
{
found = true;
break;
}
}

if (!found)
{
match = false;
break;
}
}

if (match) results.Add(c);
}

return results;
}

public CandidateSearch(List<Candidate> candidates)
{
this.candidates = candidates;
}
}

class Program
{
static void Main()
{
List<Candidate> candidates = new List<Candidate>();
List<Skill> list1 = new List<Skill>();
list1.Add(new Skill("SQL", 4));
list1.Add(new Skill("MVC", 3));
list1.Add(new Skill("C#", 5));
Candidate c1 = new Candidate("Bob B.", list1);
candidates.Add(c1);

List<Skill> list2 = new List<Skill>();
list2.Add(new Skill("SharePoint", 3));
list2.Add(new Skill("SQL", 5));
list2.Add(new Skill("C#", 5));
Candidate c2 = new Candidate("John K.", list2);
candidates.Add(c2);

List<Skill> list3 = new List<Skill>();
list3.Add(new Skill("SQL", 5));
list3.Add(new Skill("ASP.NET", 4));
list3.Add(new Skill("XML", 4));
Candidate c3 = new Candidate("Peter B.", list3);
candidates.Add(c3);

CandidateSearch candSearch = new CandidateSearch(candidates);
List<Skill> list4 = new List<Skill>();
list4.Add(new Skill("C#", 5));
List<Candidate> results = candSearch.Find(list4);
for(int i = 0; i < results.Count; i++)
{
Console.Write(results[i].Name);
if (i < results.Count - 1) Console.Write(",");
}

Console.WriteLine();

List<Skill> list5 = new List<Skill>();
list5.Add(new Skill("SQL", 5));
results = candSearch.Find(list5);
for(int i = 0; i < results.Count; i++)
{
Console.Write(results[i].Name);
if (i < results.Count - 1) Console.Write(",");
}

Console.ReadKey();
}
}



Answers (1)