Used lambda in python
output_array = lambda inp: [min(inp),max(inp)]
interface HighLow {static int[] findLargestAndSmallest(int[] nums) {// Change min and max below to be the highest and lowest values// in the nums array provided to the functionint min = 0;int max = 100;return new int[]{min, max};}}- output_array = lambda inp: [min(inp),max(inp)]
test.describe("Example Tests") tests = [ # [input, expected] [[-1,-2,-3,-4,-5,-6,-7,-8,-9,-1], [-9,-1]], [[1,-2,3,-4,-5,-6,-7,-8,-9], [-9,3]], [[1,2,3], [1,3]], [[4], [4,4]], [[9,-1], [-1,9]], ] for inp, exp in tests: test.assert_equals(output_array(inp), exp, message="Input: %s" % inp)
import org.junit.Test;import static org.junit.Assert.*;import org.junit.runners.JUnit4;- test.describe("Example Tests")
- tests = [
- # [input, expected]
- [[-1,-2,-3,-4,-5,-6,-7,-8,-9,-1], [-9,-1]],
- [[1,-2,3,-4,-5,-6,-7,-8,-9], [-9,3]],
- [[1,2,3], [1,3]],
- [[4], [4,4]],
- [[9,-1], [-1,9]],
- ]
- for inp, exp in tests:
- test.assert_equals(output_array(inp), exp, message="Input: %s" % inp)
public class SolutionTest {int[] input = new int[]{-1,-2,-3,-4,-5,-6,-7,-8,-9,-1};int[] output = new int[]{-9,-1};@Testpublic void allNegatives() {assertArrayEquals(output, HighLow.findLargestAndSmallest(input));}int[] input2 = new int[]{1,-2,3,-4,-5,-6,-7,-8,-9};int[] output2 = new int[]{-9,3};@Testpublic void test2() {assertArrayEquals(output2, HighLow.findLargestAndSmallest(input2));}int[] input123 = new int[]{1,2,3};int[] output123 = new int[]{1,3};@Testpublic void test21() {assertArrayEquals(output123, HighLow.findLargestAndSmallest(input123));}int[] input3 = new int[]{4};int[] output3 = new int[]{4,4};@Testpublic void oneItem() {assertArrayEquals(output3, HighLow.findLargestAndSmallest(input3));}int[] input4 = new int[]{9,-1};int[] output4 = new int[]{-1,9};@Testpublic void twoItems() {assertArrayEquals(output4, HighLow.findLargestAndSmallest(input4));}int[] input5 = new int[]{};int[] output5 = null;@Testpublic void emptyArray() {assertArrayEquals(output5, HighLow.findLargestAndSmallest(input5));}int[] input6 = null;int[] output6 = null;@Testpublic void nullInput() {assertArrayEquals(output6, HighLow.findLargestAndSmallest(input6));}}
is_leap = lambda n:(n%400==0 or (n%4==0 and n%100!=0))
def is_leap_year(year: str) -> bool:"""Returns True if year is a Leap Year else False."""case1: bool = year % 4 == 0case2: bool = year % 100 == 0case3: bool = year % 400 == 0return case1 and not case2 or case3- is_leap = lambda n:(n%400==0 or (n%4==0 and n%100!=0))
import unittest from solution import is_leap class TestLeapYear(unittest.TestCase): def setUp(self) -> None: self.leap_year_samples = [1584, 1588, 1592, 1596, 1600, 1604, 1608, 1612, 1616, 1620, 1624, 1628, 1632, 1636, 1640, 1644, 1648, 1652, 1656, 1660, 1664, 1668, 1672, 1676, 1680, 1684, 1688, 1692, 1696, 1704, 1708, 1712, 1716, 1720, 1724, 1728, 1732, 1736, 1740, 1744, 1748, 1752, 1756, 1760, 1764, 1768, 1772, 1776, 1780, 1784, 1788, 1792, 1796, 1804, 1808, 1812, 1816, 1820, 1824, 1828, 1832, 1836, 1840, 1844, 1848, 1852, 1856, 1860, 1864, 1868, 1872, 1876, 1880, 1884, 1888, 1892, 1896, 1904, 1908, 1912, 1916, 1920, 1924, 1928, 1932, 1936, 1940, 1944, 1948, 1952, 1956, 1960, 1964, 1968, 1972, 1976, 1980, 1984, 1988, 1992, 1996, 2000, 2004, 2008, 2012, 2016, 2020, 2024, 2028] self.non_leap_year_samples = [year + 1 for year in self.leap_year_samples] def test_leapyear_true(self): for sample in self.leap_year_samples: self.assertEqual(is_leap(sample), True) def test_leapyear_false(self): for sample in self.non_leap_year_samples: self.assertEqual(is_leap(sample), False) if __name__ == '__main__': unittest.main()
- import unittest
from solution import is_leap_year- from solution import is_leap
- class TestLeapYear(unittest.TestCase):
- def setUp(self) -> None:
- self.leap_year_samples = [1584, 1588, 1592, 1596, 1600, 1604, 1608, 1612, 1616, 1620, 1624, 1628, 1632, 1636,
- 1640, 1644, 1648, 1652, 1656, 1660, 1664, 1668, 1672, 1676, 1680, 1684, 1688, 1692,
- 1696, 1704, 1708, 1712, 1716, 1720, 1724, 1728, 1732, 1736, 1740, 1744, 1748, 1752,
- 1756, 1760, 1764, 1768, 1772, 1776, 1780, 1784, 1788, 1792, 1796, 1804, 1808, 1812,
- 1816, 1820, 1824, 1828, 1832, 1836, 1840, 1844, 1848, 1852, 1856, 1860, 1864, 1868,
- 1872, 1876, 1880, 1884, 1888, 1892, 1896, 1904, 1908, 1912, 1916, 1920, 1924, 1928,
- 1932, 1936, 1940, 1944, 1948, 1952, 1956, 1960, 1964, 1968, 1972, 1976, 1980, 1984,
- 1988, 1992, 1996, 2000, 2004, 2008, 2012, 2016, 2020, 2024, 2028]
- self.non_leap_year_samples = [year + 1 for year in self.leap_year_samples]
- def test_leapyear_true(self):
- for sample in self.leap_year_samples:
self.assertEqual(is_leap_year(sample), True)- self.assertEqual(is_leap(sample), True)
- def test_leapyear_false(self):
- for sample in self.non_leap_year_samples:
self.assertEqual(is_leap_year(sample), False)- self.assertEqual(is_leap(sample), False)
- if __name__ == '__main__':
- unittest.main()
def days(month, day): months=[28 if x==2 else 31 if ((x<8 and x%2!=0) or (x>7 and x%2==0)) else 30 for x in range(1,13)] return sum(months[0:month-1])+day
int days(int month, int day) {int i;int count = 0;int v[12]={31,28,31,30,31,30,31,31,30,31,30,31};for(i=0;i<month-1;i++) {count+=v[i];}count = count + day;return count;}- def days(month, day):
- months=[28 if x==2 else 31 if ((x<8 and x%2!=0) or (x>7 and x%2==0)) else 30 for x in range(1,13)]
- return sum(months[0:month-1])+day
#TODO: Replace examples and use TDD by writing your own tests. The code provided here is just a how-to example. #include <criterion/criterion.h> #replace with the actual method being tested #def days(month, day): import codewars_test as test from solution import days @test.describe("Fixed Tests") def basic_tests(): @test.it('Basic Test Cases') def basic_test_cases(): test.assert_equals(days(3, 1), 60) test.assert_equals(days(12, 31), 365) test.assert_equals(days(1, 1), 1) test.assert_equals(days(9, 17), 260)
// TODO: Replace examples and use TDD by writing your own tests. The code provided here is just a how-to example.- #TODO: Replace examples and use TDD by writing your own tests. The code provided here is just a how-to example.
- #include <criterion/criterion.h>
// replace with the actual method being testedint days(int month, int day);- #replace with the actual method being tested
- #def days(month, day):
Test(Test, Days) {cr_assert_eq(days(3, 1), 60);cr_assert_eq(days(12, 31), 365);cr_assert_eq(days(1, 1), 1);cr_assert_eq(days(9, 17), 260);}- import codewars_test as test
- from solution import days
- @test.describe("Fixed Tests")
- def basic_tests():
- @test.it('Basic Test Cases')
- def basic_test_cases():
- test.assert_equals(days(3, 1), 60)
- test.assert_equals(days(12, 31), 365)
- test.assert_equals(days(1, 1), 1)
- test.assert_equals(days(9, 17), 260)