NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

public class CT {
public int plus(int a,int b)
{
return a+b;
}
public int minus(int a,int b)
{
return a-b;
}
public String dream()
{
return null;
}
public String sky()
{
return "Sky has the limit";
}
public boolean even(int n)
{
return n%2==0;
}
public boolean odd(int n)
{
return n%2!=0;
}
public int[]array1(int[] x){

return x.clone();
}
public int divide(int a,int b)
{
if(b==0)
{
throw new ArithmeticException("Any number cant divide by zero");
}
return a/b;
}

}


import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.time.Duration;

import static org.junit.jupiter.api.Assertions.*;

class CTTest {
CT a = new CT();

@Test
void plus() {
assertEquals(15,a.plus(10,5));
}

@Test
void minus() {
assertNotEquals(10,a.minus(10,10));
}

@Test
void dream() {
assertNull(a.dream());
}
@BeforeAll
static void setUp()
{
System.out.println("Running @BeforeAll setup...");
}
@Test
void sky() {
assertNotNull(a.sky());
}

@Test
void even() {
assertTrue(a.even(4));
}

@Test
void odd() {
assertFalse(a.odd(2));
}

@Test
void array1() {
int[] array2 = {1,2,3,4};
assertArrayEquals(array2,a.array1(array2));
assertTimeout(Duration.ofMillis(1),()->a.plus(5,6));
}


@Test
void divide() {
assertThrows(ArithmeticException.class,()->{
a.divide(5,0);
});
}
}



import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;

import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

class NewTopicTest {
@ParameterizedTest
@ValueSource(ints ={1,2,3,4,5})
void testIsPositive(int number)
{
assertTrue(number>0);
}

@ParameterizedTest
@ValueSource(strings = {"Kazi","Halim"})
void testNotEmpty(String text)
{
assertNotNull(text);
assertFalse(text.isEmpty());
}
@ParameterizedTest
@CsvSource({
"2, 3, 5",
"3, 5, 8",
"4, 6, 10"
})

void testAddition(int a,int b,int sum)
{
assertEquals(sum,a+b);
}

@ParameterizedTest
@CsvSource({"apple","orrange","mango"})

void testIsNotEmpty(String fruit)
{
assertNotNull(fruit);
assertFalse(fruit.isEmpty());
}

@ParameterizedTest
@CsvSource({
"hello, world, [email protected]",
"java, test, [email protected]",
"unit, test, [email protected]"
})

void testUserDetail(String fname, String lname, String email)
{
assertNotNull(fname);
assertNotNull(lname);
assertTrue(email.contains("@"));
}


@ParameterizedTest
@CsvFileSource(resources = "/data.csv",numLinesToSkip = 0)

void testAdditionFromFile(int a,int b,int sum)
{
assertEquals(sum,a+b);
}
@ParameterizedTest
@CsvFileSource(resources = "/data.csv",numLinesToSkip = 3)

void testUserDetailFromFile(String fname, String lname, String email)
{
assertNotNull(fname);
assertNotNull(lname);
assertTrue(email.contains("@"));
}

static List<List<Integer>> provideNumbers() {
List<List<Integer>> data = new ArrayList<>();
data.add(List.of(2, 3, 5));
data.add(List.of(3, 5, 8));
data.add(List.of(4, 6, 10));
return data;
}

@ParameterizedTest
@MethodSource("provideNumbers")
void testSummation(int a, int b, int sum) {
assertEquals(sum, a + b);
}

static List<List<String>> provideStrings() {
List<List<String>> data = new ArrayList<>();
data.add(List.of("Hello", "World", "HelloWorld"));
data.add(List.of("Java", "Programming", "JavaProgramming"));
data.add(List.of("Unit", "Test", "UnitTest"));
return data;
}

@ParameterizedTest
@MethodSource("provideStrings")
void testConcatenation(String str1, String str2, String result) {
assertEquals(result, str1 + str2);
}




}
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.