Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 201 additions & 0 deletions UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
using part1;
using ClassLibrary1;
using Laba10;
using ClassLibrary12_4;

namespace TestProject14
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void AverageButtonCountAnalys_StackWithButtons_CalculatesAverageCorrectly()
{
// Arrange
var stack = new Stack<Dictionary<string, ControlElement>>();
var dict1 = new Dictionary<string, ControlElement>
{
{ "Element1", new Button() },
{ "Element2", new TextBox() },
{ "Element3", new Button() }
};
stack.Push(dict1);

// Act
Analysis.AverageButtonCountAnalys(stack);

// Assert
}

[TestMethod]
public void GroupByElementTypeAnalys_StackWithMixedElements_GroupsCorrectly()
{
// Arrange
var stack = new Stack<Dictionary<string, ControlElement>>();
var dict1 = new Dictionary<string, ControlElement>
{
{ "Element1", new Button() },
{ "Element2", new TextBox() },
{ "Element3", new TextBox() }
};
stack.Push(dict1);

// Act
Analysis.GroupByElementTypeAnalys(stack);

// Assert
}

[TestMethod]
public void Constructor_SetsPropertiesCorrectly()
{
// Arrange
string type = "ButtonControl";
string location = "Location1";
int capacity = 100;

// Act
var widgetManufacturer = new WidgetManufacturer(type, location, capacity);

// Assert
Assert.AreEqual(type, widgetManufacturer.WidgetType);
Assert.AreEqual(location, widgetManufacturer.Location);
Assert.AreEqual(capacity, widgetManufacturer.ProductionCapacity);
}

[TestMethod]
public void ToString_ReturnsCorrectFormat()
{
// Arrange
string type = "ButtonControl";
string location = "Location1";
int capacity = 100;
var widgetManufacturer = new WidgetManufacturer(type, location, capacity);

// Act
string result = widgetManufacturer.ToString();

// Assert
string expected = $"��� ������� - {type}, ������� - {location}, ���������������� �������� - {capacity}";
Assert.AreEqual(expected, result);
}

[TestMethod]
public void IntInput_ValidInput_ReturnsInteger()
{
// Arrange
string input = "123";
int expected = 123;

using (StringReader reader = new StringReader(input))
{
Console.SetIn(reader);

// Act
int result = part1.Utilities.IntInput("Enter an integer: ");

// Assert
Assert.AreEqual(expected, result);
}
}

[TestMethod]
public void IntInput_InvalidInputThenValid_ReturnsInteger()
{
// Arrange
string input = "abc\n123";
int expected = 123;

using (StringReader reader = new StringReader(input))
{
Console.SetIn(reader);

// Act
int result = part1.Utilities.IntInput("Enter an integer: ");

// Assert
Assert.AreEqual(expected, result);
}
}

[TestMethod]
public void SortByKeyNameAnalys_Test()
{
// Arrange
var stack = new Stack<Dictionary<string, ControlElement>>();
var dict1 = new Dictionary<string, ControlElement>
{
{ "Key3", new Button() },
{ "Key1", new TextBox() },
{ "Key2", new Button() }
};
var dict2 = new Dictionary<string, ControlElement>
{
{ "Key5", new TextBox() },
{ "Key4", new Button() }
};
stack.Push(dict1);
stack.Push(dict2);

// Act
Analysis.SortByKeyNameAnalys(stack);

// Assert
}

[TestMethod]
public void JoinWidgetManufacturerAnalys_Test()
{
// Arrange
var stack = new Stack<Dictionary<string, ControlElement>>();
var dict1 = new Dictionary<string, ControlElement>
{
{ "Key1", new Button() },
{ "Key2", new TextBox() }
};
var dict2 = new Dictionary<string, ControlElement>
{
{ "Key3", new TextBox() },
{ "Key4", new MultipleChoiceButton() }
};
stack.Push(dict1);
stack.Push(dict2);

var factories = new List<WidgetManufacturer>
{
new WidgetManufacturer("Button", "Location1", 100),
new WidgetManufacturer("TextBox", "Location2", 150),
new WidgetManufacturer("MultipleChoiceButton", "Location3", 200)
};

// Act
Analysis.JoinWidgetManufacturerAnalys(stack, factories);

// Assert
}

[TestMethod]
public void TextToKeyLengthRatioAnalys_Test()
{
// Arrange
var stack = new Stack<Dictionary<string, ControlElement>>();
var dict1 = new Dictionary<string, ControlElement>
{
{ "Key1", new TextBox { Internaltext = "Text1" } },
{ "Key2", new TextBox { Internaltext = "Text22" } }
};
var dict2 = new Dictionary<string, ControlElement>
{
{ "Key3", new Button() },
{ "Key4", new TextBox { Internaltext = "Text333" } }
};
stack.Push(dict1);
stack.Push(dict2);

// Act
Analysis.TextToKeyLengthRatioAnalys(stack);

// Assert
}
}
}
113 changes: 113 additions & 0 deletions UnitTest2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using part2;
using ClassLibrary1;
using Laba10;
using ClassLibrary12_4;
using System.Reflection.Emit;

namespace TestProject14
{
[TestClass]
public class UnitTest2
{

[TestMethod]
public void CountAnalys_Test()
{
// Arrange
var collection = new MyCollection<ControlElement>();
collection.Add(new TextBox { Internaltext = "Short" });
collection.Add(new TextBox { Internaltext = "LongText" });
collection.Add(new Button());

// Act
Analysis.CountAnalys(collection);

// Assert
}

[TestMethod]
public void AggregateAnalys_Test()
{
// Arrange
var collection = new MyCollection<ControlElement>();
collection.Add(new TextBox { Internaltext = "Short" });
collection.Add(new TextBox { Internaltext = "LongText" });
collection.Add(new Button());

// Act
Analysis.AggregateAnalys(collection);

// Assert
}

[TestMethod]
public void IntInput_ValidInput_ReturnsCorrectInteger()
{
// Arrange
var input = "123\n";
var stringReader = new StringReader(input);
Console.SetIn(stringReader);

var stringWriter = new StringWriter();
Console.SetOut(stringWriter);

// Act
int result = Utilities.IntInput("Введите число: ");

// Assert
Assert.AreEqual(123, result);
}

[TestMethod]
public void WhereAnalys_ShouldPrintOnlyButtons()
{
// Arrange
var collection = new MyCollection<ControlElement>
{
new Button { Id = "Button1" },
new TextBox { Id = "Label1" },
new Button { Id = "Button2" },
new TextBox { Id = "Label2" },
new TextBox { Id = "Label3" }
};

using (var sw = new StringWriter())
{
Console.SetOut(sw);

// Act
Analysis.WhereAnalys(collection);

// Assert
var expected = "\nТОЛЬКО КНОПКИ\n\nButton1\nButton2\n";
Assert.AreEqual(expected, sw.ToString());
}
}

[TestMethod]
public void GroupAnalys_ShouldGroupByTypeAndPrintCounts()
{
// Arrange
var collection = new MyCollection<ControlElement>
{
new Button { Id = "Button1" },
new TextBox { Id = "Label1" },
new Button { Id = "Button2" },
new TextBox { Id = "Label2" },
new TextBox { Id = "Label3" }
};

using (var sw = new StringWriter())
{
Console.SetOut(sw);

// Act
Analysis.GroupAnalys(collection);

// Assert
var expected = "\nГРУППИРОВКА ПО ТИПУ ЭЛЕМЕНТА\nButton : 2\nLabel : 3\n";
Assert.AreEqual(expected, sw.ToString().Replace("\r", ""));
}
}
}
}
Loading