Fakultas Ilmu Komputer UI

Commit 14135e4f authored by Rani Lasma Uli's avatar Rani Lasma Uli
Browse files

kill mutant1

parent 4a0036d9
......@@ -69,27 +69,18 @@ class ListViewTest(TestCase):
html = response.content.decode('utf8')
self.assertIn("oh tidak", html)
def test_to_kill_Index_mutant1(self):
# Mutant 1 output: yey, waktunya libur --> isinya 6, harusnya oh tidak
Item.objects.all().delete()
response = self.client.get(TO_DO_LIST_URL + '/mutant1')
html = response.content.decode('utf8')
self.assertIn("yey, waktunya berlibur", html)
for x in range(0,4):
# 6 items
for x in range(0,6):
Item.objects.create(text='itemey '+str(x))
# 4 items
# response = self.client.get(TO_DO_LIST_URL)
# html = response.content.decode('utf8')
# self.assertIn("sibuk tapi santai", html)
Item.objects.create(text='itemey 5')
response = self.client.get(TO_DO_LIST_URL + "/mutant1")
response = self.client.get(TO_DO_LIST_URL)
html = response.content.decode('utf8')
# expected contains "oh tidak"
# self.assertIn("oh tidak", html)
self.assertFalse("oh tidak" in html)
self.assertTrue("oh tidak" in html)
......
from django.http import HttpResponse
from django.shortcuts import redirect,render
from lists.models import Item
from unittest.mock import patch
response = {}
def index(request):
......@@ -11,8 +12,11 @@ def index(request):
items = Item.objects.all()
message = "oh tidak"
# Mutant 1: items.count() != 0
if items.count() == 0:
message = "yey, waktunya berlibur"
# Mutant 2: items.count() <= 5
elif items.count() < 5:
message = "sibuk tapi santai"
......@@ -21,41 +25,44 @@ def index(request):
'comment':message,
})
def index_mutant1(request):
if request.method == 'POST' and request.POST['item_text'] != '':
Item.objects.create(text=request.POST['item_text'])
return redirect('/')
# MUTANT IMPLEMENTATION
# def index_mutant1(request):
# if request.method == 'POST' and request.POST['item_text'] != '':
# Item.objects.create(text=request.POST['item_text'])
# return redirect('/')
items = Item.objects.all()
message = "oh tidak"
# items = Item.objects.all()
# message = "oh tidak"
# [mutant operation] mutant of items.count() == 0
if items.count() != 0:
message = "yey, waktunya berlibur"
elif items.count() < 5:
message = "sibuk tapi santai"
# # !!! mutant of items.count() == 0
# if items.count() != 0:
# message = "yey, waktunya berlibur"
# elif items.count() < 5:
# message = "sibuk tapi santai"
return render(request, 'to-do-list.html', {
'items': items,
'comment':message,
})
# return render(request, 'to-do-list.html', {
# 'items': items,
# 'comment':message,
# })
def index_mutant2(request):
if request.method == 'POST' and request.POST['item_text'] != '':
Item.objects.create(text=request.POST['item_text'])
return redirect('/')
# def index_mutant2(request):
# if request.method == 'POST' and request.POST['item_text'] != '':
# Item.objects.create(text=request.POST['item_text'])
# return redirect('/')
items = Item.objects.all()
message = "oh tidak"
# items = Item.objects.all()
# message = "oh tidak"
if items.count() == 0:
message = "yey, waktunya berlibur"
# if items.count() == 0:
# message = "yey, waktunya berlibur"
# [mutant operation] mutant of items.count() < 5
elif items.count() <= 5:
message = "sibuk tapi santai"
# # !!! mutant of items.count() < 5
# elif items.count() <= 5:
# message = "sibuk tapi santai"
return render(request, 'to-do-list.html', {
'items': items,
'comment':message,
})
# return render(request, 'to-do-list.html', {
# 'items': items,
# 'comment':message,
# })
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment