Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e0dad5c

Browse files
committed
Add 4 task
1 parent fd7221f commit e0dad5c

File tree

2 files changed

+62
-0
lines changed
  • CodingInterview/CodingInterview/csharp_tests
  • python_tests

2 files changed

+62
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using NUnit.Framework;
6+
// Task 3
7+
// Write a program to determine If the given year is a Leap year.
8+
namespace CodingInterview
9+
{
10+
public class Class4
11+
{
12+
13+
private static bool IsLeapYear(int year) {
14+
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
15+
}
16+
17+
18+
[Test]
19+
[TestCase(2000)]
20+
[TestCase(2016)]
21+
[TestCase(2020)]
22+
[TestCase(2024)]
23+
[TestCase(2400)]
24+
public void CheckIsLeapYear(int year)
25+
{
26+
Assert.AreEqual(IsLeapYear(year), true);
27+
}
28+
29+
[Test]
30+
[TestCase(1800)]
31+
[TestCase(1900)]
32+
[TestCase(2100)]
33+
[TestCase(2200)]
34+
[TestCase(2300)]
35+
public void CheckIsNotLeapYear(int year)
36+
{
37+
Assert.AreEqual(IsLeapYear(year), false);
38+
}
39+
40+
}
41+
42+
}

‎python_tests/test_4.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Task 4
2+
# Write a program to determine If the given year is a Leap year.
3+
4+
# Implementation
5+
import pytest
6+
7+
8+
def is_leap_year(year: int) -> int:
9+
return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
10+
11+
12+
# Test Section
13+
@pytest.mark.parametrize("year", [2000, 2016, 2020, 2024, 2400])
14+
def test_is_leap_year(year):
15+
assert is_leap_year(year) == True
16+
17+
18+
@pytest.mark.parametrize("year", [1800, 1900, 2100, 2200, 2300])
19+
def test_is_not_leap_year(year):
20+
assert is_leap_year(year) == False

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /