Skip to content

Commit 04959a8

Browse files
live show and tell
1 parent 4989198 commit 04959a8

9 files changed

+301
-1
lines changed

ConferenceTests.cs

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using NUnit.Framework;
4+
5+
namespace HelloWorld.Tests
6+
{
7+
[TestFixture]
8+
public class ConferenceTests
9+
{
10+
[Test]
11+
public void AddSpeaker_ShouldAddSpeakerToConference()
12+
{
13+
// Arrange
14+
var conference = new Conference("Test Conference", "Test Location", "Test Date");
15+
var speaker = new Speaker("Test Speaker", "Test Language", 30);
16+
17+
// Act
18+
conference.AddSpeaker(speaker);
19+
20+
// Assert
21+
Assert.Contains(speaker, conference.Speakers);
22+
}
23+
24+
[Test]
25+
public void RemoveSpeaker_ShouldRemoveSpeakerFromConference()
26+
{
27+
// Arrange
28+
var conference = new Conference("Test Conference", "Test Location", "Test Date");
29+
var speaker = new Speaker("Test Speaker", "Test Language", 30);
30+
conference.AddSpeaker(speaker);
31+
32+
// Act
33+
conference.RemoveSpeaker(speaker);
34+
35+
// Assert
36+
Assert.DoesNotContain(speaker, conference.Speakers);
37+
}
38+
39+
[Test]
40+
public void PrintConferenceDetails_ShouldPrintCorrectDetails()
41+
{
42+
// Arrange
43+
var conference = new Conference("Test Conference", "Test Location", "Test Date");
44+
45+
// Act
46+
using (var consoleOutput = new ConsoleOutput())
47+
{
48+
conference.PrintConferenceDetails();
49+
var output = consoleOutput.GetOuput();
50+
51+
// Assert
52+
Assert.IsTrue(output.Contains("Conference Name: Test Conference"));
53+
Assert.IsTrue(output.Contains("Conference Location: Test Location"));
54+
Assert.IsTrue(output.Contains("Conference Date: Test Date"));
55+
}
56+
}
57+
}
58+
59+
public class ConsoleOutput : IDisposable
60+
{
61+
private StringWriter stringWriter;
62+
private TextWriter originalOutput;
63+
64+
public ConsoleOutput()
65+
{
66+
stringWriter = new StringWriter();
67+
originalOutput = Console.Out;
68+
Console.SetOut(stringWriter);
69+
}
70+
71+
public string GetOuput()
72+
{
73+
return stringWriter.ToString();
74+
}
75+
76+
public void Dispose()
77+
{
78+
Console.SetOut(originalOutput);
79+
stringWriter.Dispose();
80+
}
81+
}
82+
}

SpeakerTests.cs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.IO;
3+
using NUnit.Framework;
4+
5+
namespace HelloWorld.Tests
6+
{
7+
[TestFixture]
8+
public class SpeakerTests
9+
{
10+
[Test]
11+
public void Speak_ShouldPrintHelloWorld()
12+
{
13+
// Arrange
14+
var speaker = new Speaker("Test Speaker", "Test Language", 30);
15+
16+
// Act
17+
using (var consoleOutput = new ConsoleOutput())
18+
{
19+
speaker.Speak();
20+
var output = consoleOutput.GetOuput();
21+
22+
// Assert
23+
Assert.IsTrue(output.Contains("Hello World!"));
24+
}
25+
}
26+
27+
[Test]
28+
public void GetSpeakerID_ShouldReturnIDInRange()
29+
{
30+
// Arrange
31+
var speaker = new Speaker("Test Speaker", "Test Language", 30);
32+
33+
// Act
34+
var id = speaker.SpeakerID;
35+
36+
// Assert
37+
Assert.GreaterOrEqual(id, 1);
38+
Assert.LessOrEqual(id, 1000);
39+
}
40+
}
41+
}

calc.go

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
)
7+
8+
func main() {
9+
var num1, num2 float64
10+
var operator string
11+
12+
fmt.Print("Enter first number: ")
13+
fmt.Scanln(&num1)
14+
15+
fmt.Print("Enter operator (+, -, *, /): ")
16+
fmt.Scanln(&operator)
17+
18+
fmt.Print("Enter second number: ")
19+
fmt.Scanln(&num2)
20+
21+
switch operator {
22+
case "+":
23+
fmt.Printf("Result: %.2f\n", num1+num2)
24+
case "-":
25+
fmt.Printf("Result: %.2f\n", num1-num2)
26+
case "*":
27+
fmt.Printf("Result: %.2f\n", num1*num2)
28+
case "/":
29+
if num2 != 0 {
30+
fmt.Printf("Result: %.2f\n", num1/num2)
31+
} else {
32+
fmt.Println("Error: Division by zero is not allowed.")
33+
os.Exit(1)
34+
}
35+
default:
36+
fmt.Println("Error: Invalid operator.")
37+
os.Exit(1)
38+
}
39+
}

main.cs

+58
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,62 @@ public void Speak()
8484
Console.WriteLine("Hello World!");
8585
}
8686
}
87+
88+
class Tests
89+
{
90+
// Generate a method to test the Conference class
91+
public void TestConference()
92+
{
93+
// Create a new conference
94+
Conference conference = new Conference("Tech Summit", "New York", "2021-10-10");
95+
96+
// Print conference details
97+
conference.PrintConferenceDetails();
98+
99+
// Create a new speaker
100+
Speaker speaker = new Speaker("John Doe", "English", 30);
101+
102+
// Add speaker to the conference
103+
conference.AddSpeaker(speaker);
104+
105+
// Remove speaker from the conference
106+
conference.RemoveSpeaker(speaker);
107+
}
108+
}
109+
110+
class Speakers<T>
111+
{
112+
private List<T> _speakers = new List<T>();
113+
114+
public void Add(T speaker)
115+
{
116+
_speakers.Add(speaker);
117+
}
118+
119+
public void Remove(T speaker)
120+
{
121+
_speakers.Remove(speaker);
122+
}
123+
}
124+
125+
// Main method
126+
class MainClass
127+
{
128+
static void Main(string[] args)
129+
{
130+
// Create a new instance of the Tests class
131+
Tests tests = new Tests();
132+
133+
// Run the TestConference method
134+
135+
tests.TestConference();
136+
137+
// Create a new instance of the Speaker class
138+
Speaker speaker = new Speaker("John Doe", "English", 30);
139+
140+
}
141+
}
142+
143+
144+
87145
}

main.css

+13
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,16 @@ h6 {
4141
p {
4242
margin: 0 0 10px;
4343
}
44+
45+
/* add a style for html table elements */
46+
table {
47+
border-collapse: collapse;
48+
width: 100%;
49+
}
50+
table, th, td {
51+
border: 1px solid black;
52+
}
53+
54+
55+
56+

main.java

+12
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,15 @@ public static int fib(int n) {
1212
return fib(n - 1) + fib(n - 2);
1313
}
1414
}
15+
16+
// write me a method that takes in a string and returns the string in reverse
17+
public static String reverseString(String str) {
18+
String result = "";
19+
for (int i = str.length() - 1; i >= 0; i--) {
20+
result += str.charAt(i);
21+
}
22+
return result;
23+
}
24+
25+
26+

main.py

+19
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,25 @@ def johnny_bravo(say_hello):
103103
johnny_bravo(True)
104104
johnny_bravo(False)
105105

106+
# generate a function or a method that takes input from the console and returns it
107+
def get_input():
108+
return input("Enter something: ")
109+
110+
print(get_input())
111+
112+
# create a function that will take a list of numbers and return the sum of the list
113+
def sum_list(list):
114+
total = 0
115+
for x in list:
116+
total += x
117+
return total
118+
119+
print(sum_list([1,2,3,4,5]))
120+
121+
# create a function that is called Product that will take 2 numbers and return the product of the two numbers
122+
def product(num1, num2):
123+
return num1 * num2
124+
106125

107126

108127

main.tf

+11-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,14 @@ resource "azurerm_api_management" "apim" {
2626
identity {
2727
type = "SystemAssigned"
2828
}
29-
}
29+
}
30+
31+
# create an api management product
32+
resource "azurerm_api_management_product" "product" {
33+
name = "my-product"
34+
resource_group_name = "${azurerm_resource_group.rg.name}"
35+
api_management_name = "${azurerm_api_management.apim.name}"
36+
approval_required = false
37+
subscriptions_limit = 1000
38+
state = "published"
39+
}

yk.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// write me a program that generates a hello johnny string text
2+
//
3+
4+
// Path: yk.go
5+
// Compare this snippet from main.go:
6+
7+
// // write a hello world example in go
8+
// package main
9+
10+
// import "fmt"
11+
12+
// func main() {
13+
// fmt.Println("Hello World")
14+
15+
// // return 2 integers
16+
// fmt.Println(add(1, 2))
17+
18+
19+
// // return a string
20+
21+
22+
// fmt.Println(hello("Johnny"))
23+
24+
25+
// }
26+

0 commit comments

Comments
 (0)