tests: add more test cases for LinkedList
This commit is contained in:
parent
c9eba7336c
commit
636d2b21e5
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -124,18 +125,59 @@ namespace LD_24.Code
|
|||||||
/// <param name="writer">Target file</param>
|
/// <param name="writer">Target file</param>
|
||||||
/// <param name="cells">Cell data</param>
|
/// <param name="cells">Cell data</param>
|
||||||
/// <param name="widths">Cell widths</param>
|
/// <param name="widths">Cell widths</param>
|
||||||
private static void PrintTableRow(StreamWriter writer, List<string> cells, List<int> widths)
|
private static void PrintTableRow(StreamWriter writer, LinkedList<string> cells, LinkedList<int> widths)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < widths.Count; i++)
|
foreach (var tuple in cells.Zip(widths, (a, b) => Tuple.Create(a, b)))
|
||||||
{
|
{
|
||||||
if (widths[i] > 0)
|
if (tuple.Item1[0] == '-')
|
||||||
writer.Write("| {0} ", cells[i].PadRight(widths[i]));
|
writer.Write("| {0} ", tuple.Item1.Substring(1).PadRight(tuple.Item2));
|
||||||
else
|
else
|
||||||
writer.Write("| {0} ", cells[i].PadLeft(-widths[i]));
|
writer.Write("| {0} ", tuple.Item1.PadLeft(tuple.Item2));
|
||||||
}
|
}
|
||||||
writer.WriteLine("|");
|
writer.WriteLine("|");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static LinkedList<int> FindTableWidths(LinkedList<LinkedList<string>> rows, string header, string[] columns)
|
||||||
|
{
|
||||||
|
var allWidths = new Dictionary<int, LinkedList<int>>();
|
||||||
|
|
||||||
|
int o = 0;
|
||||||
|
foreach (var column in columns)
|
||||||
|
{
|
||||||
|
allWidths.Add(o, new LinkedList<int> { column.Length });
|
||||||
|
o++;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var row in rows)
|
||||||
|
{
|
||||||
|
int p = 0;
|
||||||
|
foreach (var cell in row)
|
||||||
|
{
|
||||||
|
allWidths[p].Add(cell.Length);
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var widths = new LinkedList<int>();
|
||||||
|
int totalWidth = 3 * (columns.Length - 1);
|
||||||
|
foreach (var columnWidths in allWidths.Values)
|
||||||
|
{
|
||||||
|
int width = columnWidths.Max();
|
||||||
|
totalWidth += width;
|
||||||
|
widths.Add(width);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the header is longer than the body, make the last column wider.
|
||||||
|
// So the table is a nice rectangle when output to the file
|
||||||
|
if (header.Length > totalWidth)
|
||||||
|
{
|
||||||
|
// Make the last column a bit wider so everything lines up
|
||||||
|
widths.Add(widths.RemoveLast() + header.Length - totalWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
return widths;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Print a table to a file
|
/// Print a table to a file
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -144,58 +186,28 @@ namespace LD_24.Code
|
|||||||
/// <param name="list">Target list</param>
|
/// <param name="list">Target list</param>
|
||||||
/// <param name="columns">Column names</param>
|
/// <param name="columns">Column names</param>
|
||||||
/// <returns>A IEnumerable for inserting values for each row</returns>
|
/// <returns>A IEnumerable for inserting values for each row</returns>
|
||||||
private static IEnumerable<Tuple<T, List<string>>> PrintTable<T>(StreamWriter writer, string header, IEnumerable<T> list, params string[] columns)
|
private static IEnumerable<Tuple<T, LinkedList<string>>> PrintTable<T>(StreamWriter writer, string header, IEnumerable<T> list, params string[] columns)
|
||||||
{
|
{
|
||||||
// 0. Collect all the rows
|
// 1. Collect all the rows
|
||||||
List<List<string>> rows = new List<List<string>>();
|
LinkedList<LinkedList<string>> rows = new LinkedList<LinkedList<string>>();
|
||||||
foreach (T item in list)
|
foreach (T item in list)
|
||||||
{
|
{
|
||||||
List<string> row = new List<string>();
|
var row = new LinkedList<string>();
|
||||||
yield return Tuple.Create(item, row);
|
yield return Tuple.Create(item, row);
|
||||||
rows.Add(row);
|
rows.Add(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. Determine the width of each column
|
// 2. Determine the width of each column
|
||||||
List<int> widths = new List<int>();
|
var widths = FindTableWidths(rows, header, columns);
|
||||||
int totalWidth = 3*(columns.Length - 1);
|
int totalWidth = 3 * (columns.Length - 1) + 2 * 2 + widths.Sum();
|
||||||
for (int i = 0; i < columns.Length; i++)
|
|
||||||
{
|
|
||||||
int width = columns[i].Length;
|
|
||||||
foreach (var row in rows)
|
|
||||||
{
|
|
||||||
width = Math.Max(row[i].Length, width);
|
|
||||||
}
|
|
||||||
widths.Add(width);
|
|
||||||
totalWidth += width;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the header is longer than the body, make the last column wider.
|
|
||||||
// So the table is a nice rectangle when output to the file
|
|
||||||
if (header.Length > totalWidth)
|
|
||||||
{
|
|
||||||
widths[widths.Count - 1] += (header.Length - totalWidth);
|
|
||||||
totalWidth = header.Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
totalWidth += 2 * 2;
|
|
||||||
|
|
||||||
// 2. Adjust widths to account for aligning
|
|
||||||
for (int i = 0; i < columns.Length; i++)
|
|
||||||
{
|
|
||||||
if (columns[i][0] == '-')
|
|
||||||
{
|
|
||||||
widths[i] = -widths[i];
|
|
||||||
columns[i] = columns[i].Substring(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Display the table
|
// 3. Display the table
|
||||||
writer.WriteLine(new string('-', totalWidth));
|
writer.WriteLine(new string('-', totalWidth));
|
||||||
writer.WriteLine("| {0} |", header.PadRight(totalWidth - 4));
|
writer.WriteLine("| {0} |", header.PadRight(totalWidth - 4));
|
||||||
writer.WriteLine(new string('-', totalWidth));
|
writer.WriteLine(new string('-', totalWidth));
|
||||||
PrintTableRow(writer, new List<string>(columns), widths);
|
PrintTableRow(writer, new LinkedList<string>(columns), widths);
|
||||||
writer.WriteLine(new string('-', totalWidth));
|
writer.WriteLine(new string('-', totalWidth));
|
||||||
if (rows.Count > 0)
|
if (!rows.IsEmpty())
|
||||||
{
|
{
|
||||||
foreach (var row in rows)
|
foreach (var row in rows)
|
||||||
{
|
{
|
||||||
@ -221,7 +233,7 @@ namespace LD_24.Code
|
|||||||
foreach (var tuple in PrintTable(writer, header, orders, "Pavardė", "Vardas", "-Įtaisas", "-Įtaiso kiekis"))
|
foreach (var tuple in PrintTable(writer, header, orders, "Pavardė", "Vardas", "-Įtaisas", "-Įtaiso kiekis"))
|
||||||
{
|
{
|
||||||
Order order = tuple.Item1;
|
Order order = tuple.Item1;
|
||||||
List<string> row = tuple.Item2;
|
var row = tuple.Item2;
|
||||||
row.Add(order.CustomerSurname);
|
row.Add(order.CustomerSurname);
|
||||||
row.Add(order.CustomerName);
|
row.Add(order.CustomerName);
|
||||||
row.Add(order.ProductID);
|
row.Add(order.ProductID);
|
||||||
@ -241,7 +253,7 @@ namespace LD_24.Code
|
|||||||
foreach (var tuple in PrintTable(writer, header, orders, "Pavardė", "Vardas", "-Įtaiso kiekis, vnt.", "-Kaina, eur."))
|
foreach (var tuple in PrintTable(writer, header, orders, "Pavardė", "Vardas", "-Įtaiso kiekis, vnt.", "-Kaina, eur."))
|
||||||
{
|
{
|
||||||
Order order = tuple.Item1;
|
Order order = tuple.Item1;
|
||||||
List<string> row = tuple.Item2;
|
var row = tuple.Item2;
|
||||||
Product product = TaskUtils.FindByID(products, order.ProductID);
|
Product product = TaskUtils.FindByID(products, order.ProductID);
|
||||||
|
|
||||||
row.Add(order.CustomerSurname);
|
row.Add(order.CustomerSurname);
|
||||||
@ -262,7 +274,7 @@ namespace LD_24.Code
|
|||||||
foreach (var tuple in PrintTable(writer, header, products, "ID", "Vardas", "-Kaina"))
|
foreach (var tuple in PrintTable(writer, header, products, "ID", "Vardas", "-Kaina"))
|
||||||
{
|
{
|
||||||
Product product = tuple.Item1;
|
Product product = tuple.Item1;
|
||||||
List<string> row = tuple.Item2;
|
var row = tuple.Item2;
|
||||||
row.Add(product.ID);
|
row.Add(product.ID);
|
||||||
row.Add(product.Name);
|
row.Add(product.Name);
|
||||||
row.Add(string.Format("{0:f2}", product.Price));
|
row.Add(string.Format("{0:f2}", product.Price));
|
||||||
@ -281,7 +293,7 @@ namespace LD_24.Code
|
|||||||
foreach (var tuple in PrintTable(writer, header, popularProducts, "ID", "Vardas", "-Įtaisų kiekis, vnt.", "-Įtaisų kaina, eur."))
|
foreach (var tuple in PrintTable(writer, header, popularProducts, "ID", "Vardas", "-Įtaisų kiekis, vnt.", "-Įtaisų kaina, eur."))
|
||||||
{
|
{
|
||||||
Product product = tuple.Item1;
|
Product product = tuple.Item1;
|
||||||
List<string> row = tuple.Item2;
|
var row = tuple.Item2;
|
||||||
int sales = TaskUtils.CountProductSales(orders, product.ID);
|
int sales = TaskUtils.CountProductSales(orders, product.ID);
|
||||||
row.Add(product.ID);
|
row.Add(product.ID);
|
||||||
row.Add(product.Name);
|
row.Add(product.Name);
|
||||||
|
@ -6,7 +6,11 @@ using System.Web;
|
|||||||
|
|
||||||
namespace LD_24.Code
|
namespace LD_24.Code
|
||||||
{
|
{
|
||||||
public class LinkedList<T> : IEnumerable<T>
|
/// <summary>
|
||||||
|
/// Generic linked list class. Used for storing a list of values.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">Target type</typeparam>
|
||||||
|
public class LinkedList<T> : IEnumerable<T>, IComparable<LinkedList<T>>, IEquatable<LinkedList<T>>
|
||||||
where T : IComparable<T>, IEquatable<T>
|
where T : IComparable<T>, IEquatable<T>
|
||||||
{
|
{
|
||||||
class Node
|
class Node
|
||||||
@ -24,9 +28,32 @@ namespace LD_24.Code
|
|||||||
private Node head;
|
private Node head;
|
||||||
private Node tail;
|
private Node tail;
|
||||||
|
|
||||||
public void Add(T customer)
|
/// <summary>
|
||||||
|
/// Creates an empty linked list
|
||||||
|
/// </summary>
|
||||||
|
public LinkedList()
|
||||||
{
|
{
|
||||||
Node node = new Node(customer);
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates an clone of a given enumerable value/list
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="other">Cloned enumerable</param>
|
||||||
|
public LinkedList(IEnumerable<T> other)
|
||||||
|
{
|
||||||
|
foreach (var value in other)
|
||||||
|
{
|
||||||
|
Add(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add a single element to the linked list
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
public void Add(T value)
|
||||||
|
{
|
||||||
|
Node node = new Node(value);
|
||||||
if (tail != null && head != null)
|
if (tail != null && head != null)
|
||||||
{
|
{
|
||||||
tail.Next = node;
|
tail.Next = node;
|
||||||
@ -39,6 +66,62 @@ namespace LD_24.Code
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes the last element from this list
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The last elements values or the default value if empty</returns>
|
||||||
|
public T RemoveLast()
|
||||||
|
{
|
||||||
|
if (head == null)
|
||||||
|
{
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
|
||||||
|
Node prev = null;
|
||||||
|
Node current = head;
|
||||||
|
while (current.Next != null)
|
||||||
|
{
|
||||||
|
prev = current;
|
||||||
|
current = current.Next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prev != null)
|
||||||
|
{
|
||||||
|
prev.Next = null;
|
||||||
|
tail = prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prev == null)
|
||||||
|
{
|
||||||
|
head = null;
|
||||||
|
tail = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return current.Data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the first element
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The first element</returns>
|
||||||
|
public T GetFirst()
|
||||||
|
{
|
||||||
|
return head != null ? head.Data : default;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the first element
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The first element</returns>
|
||||||
|
public T GetLast()
|
||||||
|
{
|
||||||
|
return tail != null ? tail.Data : default;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Count how many elemnts are stored in this list
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Number of stored elements</returns>
|
||||||
public int Count()
|
public int Count()
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@ -49,11 +132,19 @@ namespace LD_24.Code
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if the linked list is empty,
|
||||||
|
/// what did you expect?
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A boolean</returns>
|
||||||
public bool IsEmpty()
|
public bool IsEmpty()
|
||||||
{
|
{
|
||||||
return head == null;
|
return head == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sorts this linked list
|
||||||
|
/// </summary>
|
||||||
public void Sort()
|
public void Sort()
|
||||||
{
|
{
|
||||||
for (Node nodeA = head; nodeA != null; nodeA = nodeA.Next)
|
for (Node nodeA = head; nodeA != null; nodeA = nodeA.Next)
|
||||||
@ -73,20 +164,99 @@ namespace LD_24.Code
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A human-readable string for debuging purposes
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Debug string</returns>
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return String.Format("LinkedList<{0}>{ Count = '{0}' }", Count());
|
return string.Format("LinkedList<{0}>( Count = {0} )", Count());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enumerate over all the elements of the list
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>An enumerator</returns>
|
||||||
public IEnumerator<T> GetEnumerator()
|
public IEnumerator<T> GetEnumerator()
|
||||||
{
|
{
|
||||||
for (Node d = head; d != null; d = d.Next)
|
for (Node d = head; d != null; d = d.Next)
|
||||||
yield return d.Data;
|
yield return d.Data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Enumerate over all the elements of the list
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>An enumerator</returns>
|
||||||
IEnumerator IEnumerable.GetEnumerator()
|
IEnumerator IEnumerable.GetEnumerator()
|
||||||
{
|
{
|
||||||
return GetEnumerator();
|
return GetEnumerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compares the ordering 2 lists
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="other">Other list</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int CompareTo(LinkedList<T> other)
|
||||||
|
{
|
||||||
|
var otherEnumerator = other.GetEnumerator();
|
||||||
|
foreach (var value in this)
|
||||||
|
{
|
||||||
|
if (otherEnumerator.MoveNext())
|
||||||
|
{
|
||||||
|
int comparison = value.CompareTo(otherEnumerator.Current);
|
||||||
|
if (comparison != 0)
|
||||||
|
{
|
||||||
|
return comparison;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (otherEnumerator.MoveNext())
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if 2 linked lists have the same values stored
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="other">Other linked list</param>
|
||||||
|
/// <returns>True if they both store the same values</returns>
|
||||||
|
public bool Equals(LinkedList<T> other)
|
||||||
|
{
|
||||||
|
var otherEnumerator = other.GetEnumerator();
|
||||||
|
foreach (var value in this)
|
||||||
|
{
|
||||||
|
if (otherEnumerator.MoveNext())
|
||||||
|
{
|
||||||
|
if (!value.Equals(otherEnumerator.Current))
|
||||||
|
{
|
||||||
|
// This is the case, when some elements in between the lists are different
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// This is the case when the other linked list runs out of values, while this still has more.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (otherEnumerator.MoveNext())
|
||||||
|
{
|
||||||
|
// This is the case, when the other linked list still had some left over values.
|
||||||
|
// That means it had more elements that this one.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is the case, when everything is the same.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -27,6 +27,13 @@ namespace LD_24.Code
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int ProductAmount { get; set; }
|
public int ProductAmount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new order
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="customerSurname">The customers surname</param>
|
||||||
|
/// <param name="customerName">The customers name</param>
|
||||||
|
/// <param name="productID">Product ID</param>
|
||||||
|
/// <param name="productAmount">Product amount</param>
|
||||||
public Order(string customerSurname, string customerName, string productID, int productAmount)
|
public Order(string customerSurname, string customerName, string productID, int productAmount)
|
||||||
{
|
{
|
||||||
CustomerSurname = customerSurname;
|
CustomerSurname = customerSurname;
|
||||||
@ -35,11 +42,11 @@ namespace LD_24.Code
|
|||||||
ProductAmount = productAmount;
|
ProductAmount = productAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
/// <summary>
|
||||||
{
|
/// Compares the sorting order of this and other.
|
||||||
return String.Format("Order{Name = '{0}'}", CustomerName);
|
/// </summary>
|
||||||
}
|
/// <param name="other"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public int CompareTo(Order other)
|
public int CompareTo(Order other)
|
||||||
{
|
{
|
||||||
if (ProductAmount > other.ProductAmount)
|
if (ProductAmount > other.ProductAmount)
|
||||||
@ -62,6 +69,11 @@ namespace LD_24.Code
|
|||||||
return Equals(other) ? 0 : -1;
|
return Equals(other) ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compare if this order has the same sorting order as another one.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="other"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public bool Equals(Order other)
|
public bool Equals(Order other)
|
||||||
{
|
{
|
||||||
return CustomerSurname == other.CustomerSurname &&
|
return CustomerSurname == other.CustomerSurname &&
|
||||||
@ -79,5 +91,10 @@ namespace LD_24.Code
|
|||||||
hashCode = hashCode * -1521134295 + ProductAmount.GetHashCode();
|
hashCode = hashCode * -1521134295 + ProductAmount.GetHashCode();
|
||||||
return hashCode;
|
return hashCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return String.Format("Order{Name = '{0}'}", CustomerName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -23,6 +23,12 @@ namespace LD_24.Code
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public decimal Price { get; set; }
|
public decimal Price { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new product
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="iD">ID</param>
|
||||||
|
/// <param name="name">Name</param>
|
||||||
|
/// <param name="price">Price</param>
|
||||||
public Product(string iD, string name, decimal price)
|
public Product(string iD, string name, decimal price)
|
||||||
{
|
{
|
||||||
ID = iD;
|
ID = iD;
|
||||||
@ -30,11 +36,11 @@ namespace LD_24.Code
|
|||||||
Price = price;
|
Price = price;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
/// <summary>
|
||||||
{
|
/// Check if this has the same sorting order as othe product
|
||||||
return String.Format("Product{ID = '{0}'}", ID);
|
/// </summary>
|
||||||
}
|
/// <param name="other"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public bool Equals(Product other)
|
public bool Equals(Product other)
|
||||||
{
|
{
|
||||||
return ID == other.ID &&
|
return ID == other.ID &&
|
||||||
@ -55,5 +61,10 @@ namespace LD_24.Code
|
|||||||
{
|
{
|
||||||
return ID.CompareTo(other.ID);
|
return ID.CompareTo(other.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return String.Format("Product{ID = '{0}'}", ID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,11 +17,21 @@ namespace LD_24
|
|||||||
{
|
{
|
||||||
private const string outputFilename = "App_Data/Rezultatai.txt";
|
private const string outputFilename = "App_Data/Rezultatai.txt";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Function that runs when the page loads
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
protected void Page_Load(object sender, EventArgs e)
|
protected void Page_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
FindControl("ResultsDiv").Visible = false;
|
FindControl("ResultsDiv").Visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Functions that rusn when the button is clicked
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
protected void Button1_Click(object sender, EventArgs e)
|
protected void Button1_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
int n = int.Parse(TextBox1.Text);
|
int n = int.Parse(TextBox1.Text);
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
For more information on how to configure your ASP.NET application, please visit
|
For more information on how to configure your ASP.NET application, please visit
|
||||||
https://go.microsoft.com/fwlink/?LinkId=169433
|
https://go.microsoft.com/fwlink/?LinkId=169433
|
||||||
@ -15,13 +14,225 @@
|
|||||||
</system.web>
|
</system.web>
|
||||||
<system.codedom>
|
<system.codedom>
|
||||||
<compilers>
|
<compilers>
|
||||||
<compiler language="c#;cs;csharp" extension=".cs"
|
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
|
||||||
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
|
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
|
||||||
warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
|
|
||||||
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
|
|
||||||
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
|
|
||||||
warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
|
|
||||||
</compilers>
|
</compilers>
|
||||||
</system.codedom>
|
</system.codedom>
|
||||||
|
|
||||||
|
<runtime>
|
||||||
|
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Xml.XPath.XDocument" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Xml.XmlSerializer" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Xml.XDocument" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Xml.ReaderWriter" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.ValueTuple" publicKeyToken="CC7B13FFCD2DDD51" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Threading.Timer" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Threading.Tasks.Parallel" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Threading.Overlapped" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Threading" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Text.RegularExpressions" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Text.Encoding.Extensions" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Text.Encoding" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Security.SecureString" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Security.Principal" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Security.Cryptography.Algorithms" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Runtime.Serialization.Xml" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.1.3.0" newVersion="4.1.3.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Runtime.Serialization.Primitives" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Runtime.Serialization.Json" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Runtime.Numerics" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Runtime.InteropServices" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Runtime.Extensions" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Runtime" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Resources.ResourceManager" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Reflection.Primitives" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Reflection.Extensions" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Reflection" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.ObjectModel" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Net.Sockets" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Net.Requests" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Net.Primitives" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Net.NetworkInformation" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Net.Http" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Linq.Queryable" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Linq.Parallel" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Linq.Expressions" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Linq" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.IO" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.IO.Compression" publicKeyToken="B77A5C561934E089" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Globalization.Extensions" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Globalization" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Dynamic.Runtime" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Diagnostics.Tracing" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Diagnostics.Tools" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Diagnostics.StackTrace" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Diagnostics.Debug" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Diagnostics.Contracts" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Data.Common" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.ComponentModel.EventBasedAsync" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.ComponentModel" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Collections" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity name="System.Collections.Concurrent" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
|
||||||
|
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
</assemblyBinding>
|
||||||
|
</runtime>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
17
L3/LD_24Tests/IntLinkedList.cs
Normal file
17
L3/LD_24Tests/IntLinkedList.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
using LD_24.Code;
|
||||||
|
using Bogus;
|
||||||
|
|
||||||
|
namespace LD_24Tests
|
||||||
|
{
|
||||||
|
public class IntLinkedListTests : LinkedListTests<int>
|
||||||
|
{
|
||||||
|
private readonly Faker faker = new Faker("en");
|
||||||
|
|
||||||
|
protected override int CreateItem()
|
||||||
|
{
|
||||||
|
return faker.Random.Number(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Bogus" Version="34.0.1" />
|
<PackageReference Include="Bogus" Version="34.0.1" />
|
||||||
<PackageReference Include="FluentAssertions" Version="6.5.1" />
|
<PackageReference Include="FluentAssertions" Version="6.6.0" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
|
||||||
<PackageReference Include="xunit" Version="2.4.1" />
|
<PackageReference Include="xunit" Version="2.4.1" />
|
||||||
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
|
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
|
||||||
|
@ -3,71 +3,346 @@ using Xunit;
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using LD_24.Code;
|
using LD_24.Code;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace LD_24Tests
|
namespace LD_24Tests
|
||||||
{
|
{
|
||||||
public abstract class LinkedListTests<T>
|
public abstract class LinkedListTests<T>
|
||||||
where T : IComparable<T>, IEquatable<T>
|
where T : IComparable<T>, IEquatable<T>
|
||||||
{
|
{
|
||||||
protected abstract LinkedList<T> CreateNewList();
|
|
||||||
protected abstract T CreateItem();
|
protected abstract T CreateItem();
|
||||||
|
|
||||||
[Fact]
|
private LinkedList<T> CreateLoadedList(int count)
|
||||||
public void New_List_Is_Empty()
|
|
||||||
{
|
{
|
||||||
LinkedList<T> list = CreateNewList();
|
var list = new LinkedList<T>();
|
||||||
|
|
||||||
list.IsEmpty().Should().BeTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void Assert_List_Is_Not_Empty()
|
|
||||||
{
|
|
||||||
LinkedList<T> list = CreateNewList();
|
|
||||||
|
|
||||||
list.Add(CreateItem());
|
|
||||||
|
|
||||||
list.IsEmpty().Should().BeFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData(0)]
|
|
||||||
[InlineData(1)]
|
|
||||||
[InlineData(5)]
|
|
||||||
public void Retrieve_How_Many_Were_Added(int count)
|
|
||||||
{
|
|
||||||
LinkedList<T> list = CreateNewList();
|
|
||||||
|
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
list.Add(CreateItem());
|
list.Add(CreateItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
[Trait("TestedMethod", "Constructor")]
|
||||||
|
public void CreatingList_Shouldnt_Throw()
|
||||||
|
{
|
||||||
|
Action action = () => new LinkedList<T>();
|
||||||
|
|
||||||
|
action.Should().NotThrow();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[Trait("TestedMethod", "Constructor")]
|
||||||
|
[InlineData(0)]
|
||||||
|
[InlineData(1)]
|
||||||
|
[InlineData(5)]
|
||||||
|
public void CreateList_From_Other_List(int count)
|
||||||
|
{
|
||||||
|
var list = CreateLoadedList(count);
|
||||||
|
var newList = new LinkedList<T>(list);
|
||||||
|
|
||||||
|
list.Equals(newList).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[Trait("TestedMethod", "Add")]
|
||||||
|
[InlineData(0)]
|
||||||
|
[InlineData(1)]
|
||||||
|
[InlineData(5)]
|
||||||
|
public void Adding_Should_Not_Throw(int count)
|
||||||
|
{
|
||||||
|
LinkedList<T> list = CreateLoadedList(count);
|
||||||
|
Action task = () => list.Add(CreateItem());
|
||||||
|
|
||||||
|
task.Should().NotThrow();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
[Trait("TestedMethod", "IsEmpty")]
|
||||||
|
public void New_List_Is_Empty()
|
||||||
|
{
|
||||||
|
LinkedList<T> list = new LinkedList<T>();
|
||||||
|
|
||||||
|
list.IsEmpty().Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
[Trait("TestedMethod", "IsEmpty")]
|
||||||
|
public void Assert_List_Is_Not_Empty()
|
||||||
|
{
|
||||||
|
LinkedList<T> list = new LinkedList<T>();
|
||||||
|
list.Add(CreateItem());
|
||||||
|
|
||||||
|
list.IsEmpty().Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[Trait("TestedMethod", "IsEmpty")]
|
||||||
|
[InlineData(0)]
|
||||||
|
[InlineData(1)]
|
||||||
|
[InlineData(5)]
|
||||||
|
public void Is_Empty_Should_Not_Throw(int count)
|
||||||
|
{
|
||||||
|
LinkedList<T> list = CreateLoadedList(count);
|
||||||
|
Action task = () => list.Add(CreateItem());
|
||||||
|
|
||||||
|
task.Should().NotThrow();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[Trait("TestedMethod", "Count")]
|
||||||
|
[InlineData(0)]
|
||||||
|
[InlineData(1)]
|
||||||
|
[InlineData(5)]
|
||||||
|
public void Retrieve_How_Many_Were_Added(int count)
|
||||||
|
{
|
||||||
|
LinkedList<T> list = CreateLoadedList(count);
|
||||||
|
|
||||||
list.Count().Should().Be(count);
|
list.Count().Should().Be(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void IEnumerable_Is_Implemented_Correctly()
|
[Trait("TestedMethod", "GetLast")]
|
||||||
|
public void Assert_Last_Element_When_Empty_Doesnt_Throw()
|
||||||
{
|
{
|
||||||
LinkedList<T> list = CreateNewList();
|
LinkedList<T> list = new LinkedList<T>();
|
||||||
|
Func<T> task = () => list.GetLast();
|
||||||
|
|
||||||
var item1 = CreateItem();
|
task.Should().NotThrow();
|
||||||
var item2 = CreateItem();
|
}
|
||||||
var item3 = CreateItem();
|
|
||||||
|
|
||||||
list.Add(item1);
|
[Theory]
|
||||||
list.Add(item2);
|
[Trait("TestedMethod", "GetLast")]
|
||||||
list.Add(item3);
|
[InlineData(0)]
|
||||||
|
[InlineData(1)]
|
||||||
var newList = new System.Collections.Generic.List<T>();
|
[InlineData(5)]
|
||||||
foreach (var item in list)
|
public void Assert_Last_Element_Value(int count)
|
||||||
{
|
{
|
||||||
newList.Add(item);
|
var list = CreateLoadedList(count);
|
||||||
|
var last = CreateItem();
|
||||||
|
list.Add(last);
|
||||||
|
|
||||||
|
list.GetLast().Should().Be(last);
|
||||||
}
|
}
|
||||||
|
|
||||||
newList[0].Should().Be(item1);
|
[Fact]
|
||||||
newList[1].Should().Be(item2);
|
[Trait("TestedMethod", "GetFirst")]
|
||||||
newList[2].Should().Be(item3);
|
public void Assert_First_Element_When_Empty()
|
||||||
|
{
|
||||||
|
LinkedList<T> list = new LinkedList<T>();
|
||||||
|
|
||||||
|
list.GetFirst().Should().Be(default);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
[Trait("TestedMethod", "GetFirst")]
|
||||||
|
public void Assert_First_Element_When_Empty_Doesnt_Throw()
|
||||||
|
{
|
||||||
|
LinkedList<T> list = new LinkedList<T>();
|
||||||
|
Func<T> task = () => list.GetFirst();
|
||||||
|
|
||||||
|
task.Should().NotThrow();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[Trait("TestedMethod", "GetFirst")]
|
||||||
|
[InlineData(0)]
|
||||||
|
[InlineData(1)]
|
||||||
|
[InlineData(5)]
|
||||||
|
public void Assert_First_Element_Value(int count)
|
||||||
|
{
|
||||||
|
var list = new LinkedList<T>();
|
||||||
|
var first = CreateItem();
|
||||||
|
list.Add(first);
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
list.Add(CreateItem());
|
||||||
|
|
||||||
|
list.GetFirst().Should().Be(first);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[Trait("TestedMethod", "RemoveLast")]
|
||||||
|
[InlineData(0)]
|
||||||
|
[InlineData(1)]
|
||||||
|
[InlineData(5)]
|
||||||
|
public void RemoveLast_Shouldnt_Throw(int count)
|
||||||
|
{
|
||||||
|
var list = CreateLoadedList(count);
|
||||||
|
Action action = () => list.RemoveLast();
|
||||||
|
|
||||||
|
action.Should().NotThrow();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[Trait("TestedMethod", "RemoveLast")]
|
||||||
|
[InlineData(1)]
|
||||||
|
[InlineData(5)]
|
||||||
|
public void RemoveLast_Returns_Removed_Value(int count)
|
||||||
|
{
|
||||||
|
var list = CreateLoadedList(count);
|
||||||
|
var last = list.GetLast();
|
||||||
|
|
||||||
|
list.RemoveLast().Should().Be(last);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[Trait("TestedMethod", "RemoveLast")]
|
||||||
|
[InlineData(1)]
|
||||||
|
[InlineData(5)]
|
||||||
|
public void After_RemoveLast_Length_Should_Decrease(int count)
|
||||||
|
{
|
||||||
|
var list = CreateLoadedList(count);
|
||||||
|
|
||||||
|
list.RemoveLast();
|
||||||
|
list.Count().Should().Be(count-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
[Trait("TestedMethod", "RemoveLast")]
|
||||||
|
public void RemoveLast_Does_Nothing_In_Empty_List()
|
||||||
|
{
|
||||||
|
var list = new LinkedList<T>();
|
||||||
|
|
||||||
|
list.RemoveLast();
|
||||||
|
list.Count().Should().Be(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
[Trait("TestedMethod", "RemoveLast")]
|
||||||
|
public void RemoveLast_Returns_Default_In_Empty_List()
|
||||||
|
{
|
||||||
|
var list = new LinkedList<T>();
|
||||||
|
|
||||||
|
list.RemoveLast().Should().Be(default);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[Trait("TestedMethod", "IEnumerable")]
|
||||||
|
[InlineData(0)]
|
||||||
|
[InlineData(1)]
|
||||||
|
[InlineData(5)]
|
||||||
|
public void IEnumerable_Is_Implemented_Correctly(int count)
|
||||||
|
{
|
||||||
|
var genericList = new System.Collections.Generic.List<T>();
|
||||||
|
LinkedList<T> list = new LinkedList<T>();
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
var item = CreateItem();
|
||||||
|
list.Add(item);
|
||||||
|
genericList.Add(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Checks the enumerators "list" and "genericList" contain the same values
|
||||||
|
genericList.Zip(list, (a, b) => a.Equals(b)).All((t) => t).Should();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
[Trait("TestedMethod", "ToString")]
|
||||||
|
public void Assert_ToString_Is_Overridden()
|
||||||
|
{
|
||||||
|
var list = new LinkedList<T>();
|
||||||
|
Assert.True(list.ToString() != list.GetType().ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[Trait("TestedMethod", "Equals")]
|
||||||
|
[InlineData(0)]
|
||||||
|
[InlineData(1)]
|
||||||
|
[InlineData(5)]
|
||||||
|
public void Check_If_Lists_Are_Equal(int count)
|
||||||
|
{
|
||||||
|
var list1 = CreateLoadedList(count);
|
||||||
|
var list2 = new LinkedList<T>(list1);
|
||||||
|
|
||||||
|
list1.Equals(list2).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[Trait("TestedMethod", "Equals")]
|
||||||
|
[InlineData(1)]
|
||||||
|
[InlineData(5)]
|
||||||
|
public void Check_If_Lists_Arent_Equal(int count)
|
||||||
|
{
|
||||||
|
var list1 = CreateLoadedList(count);
|
||||||
|
var list2 = CreateLoadedList(count);
|
||||||
|
|
||||||
|
list1.Equals(list2).Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[Trait("TestedMethod", "Equals")]
|
||||||
|
[InlineData(1)]
|
||||||
|
[InlineData(5)]
|
||||||
|
public void Check_If_Lists_Arent_Equal_By_Size(int count)
|
||||||
|
{
|
||||||
|
var list1 = CreateLoadedList(count);
|
||||||
|
var list2 = new LinkedList<T>(list1);
|
||||||
|
list2.RemoveLast();
|
||||||
|
|
||||||
|
list1.Equals(list2).Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[Trait("TestedMethod", "Sort")]
|
||||||
|
[InlineData(0)]
|
||||||
|
[InlineData(1)]
|
||||||
|
[InlineData(5)]
|
||||||
|
public void Sort_Shouldnt_Throw(int count)
|
||||||
|
{
|
||||||
|
var list = CreateLoadedList(count);
|
||||||
|
Action action = () => list.Sort();
|
||||||
|
|
||||||
|
action.Should().NotThrow();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
[Trait("TestedMethod", "Sort")]
|
||||||
|
public void Sort_Does_Nothing_On_Empty_List()
|
||||||
|
{
|
||||||
|
var list = new LinkedList<T>();
|
||||||
|
var listCopy = new LinkedList<T>(list);
|
||||||
|
list.Sort();
|
||||||
|
|
||||||
|
list.Equals(listCopy).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[Trait("TestedMethod", "Sort")]
|
||||||
|
[InlineData(0)]
|
||||||
|
[InlineData(1)]
|
||||||
|
[InlineData(5)]
|
||||||
|
public void Items_In_Correct_Order_After_Sort(int count)
|
||||||
|
{
|
||||||
|
var list = CreateLoadedList(count);
|
||||||
|
list.Sort();
|
||||||
|
|
||||||
|
var itemPairs = list.Zip(list.Skip(1), (a, b) => Tuple.Create(a, b));
|
||||||
|
foreach (var tuple in itemPairs)
|
||||||
|
{
|
||||||
|
Assert.True(tuple.Item1.CompareTo(tuple.Item2) >= 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[Trait("TestedMethod", "Sort")]
|
||||||
|
[InlineData(0)]
|
||||||
|
[InlineData(1)]
|
||||||
|
[InlineData(5)]
|
||||||
|
public void Does_Nothing_If_Already_Sorted(int count)
|
||||||
|
{
|
||||||
|
var list = CreateLoadedList(count);
|
||||||
|
list.Sort();
|
||||||
|
|
||||||
|
var listCopy = new LinkedList<T>(list);
|
||||||
|
list.Sort();
|
||||||
|
|
||||||
|
list.Equals(listCopy).Should().BeTrue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,8 @@ namespace LD_24Tests
|
|||||||
{
|
{
|
||||||
public class OrderLinkedListTests : LinkedListTests<Order>
|
public class OrderLinkedListTests : LinkedListTests<Order>
|
||||||
{
|
{
|
||||||
private Faker faker = new Faker("en");
|
private readonly Faker faker = new Faker("en");
|
||||||
|
|
||||||
protected override LinkedList<Order> CreateNewList() => new LinkedList<Order>();
|
|
||||||
protected override Order CreateItem()
|
protected override Order CreateItem()
|
||||||
{
|
{
|
||||||
string customerSurname = faker.Name.FindName();
|
string customerSurname = faker.Name.FindName();
|
||||||
|
17
L3/LD_24Tests/StringLinkedListTests.cs
Normal file
17
L3/LD_24Tests/StringLinkedListTests.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
using Bogus;
|
||||||
|
using LD_24.Code;
|
||||||
|
|
||||||
|
namespace LD_24Tests
|
||||||
|
{
|
||||||
|
public class StringLinkedListTests : LinkedListTests<string>
|
||||||
|
{
|
||||||
|
private readonly Faker faker = new Faker("en");
|
||||||
|
|
||||||
|
protected override string CreateItem()
|
||||||
|
{
|
||||||
|
return faker.Name.FullName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user