Skip to content

Instantly share code, notes, and snippets.

@henebb
Created February 2, 2015 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henebb/a4c3ac25399858234e3f to your computer and use it in GitHub Desktop.
Save henebb/a4c3ac25399858234e3f to your computer and use it in GitHub Desktop.
MovieNight - ApprovalTests Combination Tests
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MovieNight
{
public class MovieNight
{
public string GetMovieRecomendations(string name, int age, double time, Sex gender, bool isMarried)
{
var sb = new StringBuilder();
if (gender == Sex.Male)
{
if (age < 18)
{
sb.AppendFormat("Master {0} ", name);
}
else
{
sb.AppendFormat("Mr. {0} ", name);
}
}
else
{
if (isMarried)
{
sb.AppendFormat("Mrs. {0} ", name);
}
else
{
if (age < 18)
{
sb.AppendFormat("Miss {0} ", name);
}
else
{
sb.AppendFormat("Ms. {0} ", name);
}
}
}
var movies = GetMovies().Where(m => m.MinimumAge <= age);
sb.Append("should watch");
foreach (var movie in movies)
{
if (time > movie.Length)
{
time -= movie.Length;
sb.AppendFormat(" {0},", movie.Title);
}
}
return sb.ToString();
}
private static IEnumerable<Movie> GetMovies()
{
return new[]
{
new Movie("A Most Wanted Man", 2.02, Rating.R),
new Movie("Sex Tape", 1.34, Rating.R),
new Movie("Medicinen", 1.55, Rating.PG),
new Movie("The Grand Budapest Hotel", 1.4, Rating.PG13),
new Movie("Let's be Cops", 1.44, Rating.PG13),
new Movie("Hackers", 1.5, Rating.G),
new Movie("Joe", 1.57, Rating.R),
new Movie("Guardians of the Galaxy", 2.01, Rating.PG13),
new Movie("12 Years a Slave", 2.13, Rating.R),
new Movie("Flygplan 2: Räddningstjänsten - Svenskt tal", 1.20, Rating.G),
new Movie("American Hustle", 2.18, Rating.R),
new Movie("Draktränaren 2 - Svenskt tal", 1.42, Rating.PG)
};
}
}
public class Movie
{
public Movie(string title, double length, Rating rating)
{
Title = title;
Length = length;
switch (rating)
{
case Rating.G:
MinimumAge = 0;
break;
case Rating.PG:
MinimumAge = 7;
break;
case Rating.PG13:
MinimumAge = 11;
break;
case Rating.R:
MinimumAge = 15;
break;
}
}
public int MinimumAge { get; set; }
public double Length { get; set; }
public string Title { get; set; }
}
public enum Rating
{
G,
PG,
PG13,
R,
NC17
}
public enum Sex
{
Male,
Female
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment