Skip to content

Commit

Permalink
Merge pull request #197 from Divyeshhhh/tutotest
Browse files Browse the repository at this point in the history
write tests for TutorialModel
  • Loading branch information
creme332 authored Aug 7, 2024
2 parents 58d6b1e + 3490afa commit 3583905
Showing 1 changed file with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.github.creme332.tests.model;

import static org.junit.Assert.*;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.junit.Test;
import com.github.creme332.model.TutorialModel;

public class TutorialModelTest {

@Test
public void testTitle() {
String title = "Java Programming Basics";
TutorialModel tutorial = new TutorialModel(title);
assertEquals(title, tutorial.getTitle());
}

@Test
public void testKeywordsFromTitle() {
String title = "Java Programming Basics";
TutorialModel tutorial = new TutorialModel(title);
Set<String> expectedKeywords = new HashSet<>(Arrays.asList("java", "programming", "basics"));
Set<String> actualKeywords = new HashSet<>(Arrays.asList(tutorial.getKeywords()));
assertEquals(expectedKeywords, actualKeywords);
}

@Test
public void testAddValidKeyword() {
TutorialModel tutorial = new TutorialModel("Test Title");
tutorial.addKeyword("keyword");
Set<String> expectedKeywords = new HashSet<>(Arrays.asList("test", "title", "keyword"));
Set<String> actualKeywords = new HashSet<>(Arrays.asList(tutorial.getKeywords()));
assertEquals(expectedKeywords, actualKeywords);
}

@Test
public void testAddInvalidKeyword() {
TutorialModel tutorial = new TutorialModel("Test Title");
tutorial.addKeyword("kw");
Set<String> expectedKeywords = new HashSet<>(Arrays.asList("test", "title"));
Set<String> actualKeywords = new HashSet<>(Arrays.asList(tutorial.getKeywords()));
assertEquals(expectedKeywords, actualKeywords);
}

@Test
public void testCaseInsensitivityOfKeywords() {
TutorialModel tutorial = new TutorialModel("Test Title");
tutorial.addKeyword("Keyword");
tutorial.addKeyword("KEYWORD");
tutorial.addKeyword("keyword");
Set<String> expectedKeywords = new HashSet<>(Arrays.asList("test", "title", "keyword"));
Set<String> actualKeywords = new HashSet<>(Arrays.asList(tutorial.getKeywords()));
assertEquals(expectedKeywords, actualKeywords);
}
}

0 comments on commit 3583905

Please sign in to comment.