Question: Please code in kotlin all needing to be changed so that the tests you run in test code file run without error wif is an

Please code in kotlin

all needing to be changed so that the tests you run in test code file run without error

wif is an infix function which is an extension to the String class. Read test1a() to see what it is expected to return.

total is a function that takes any number of arguments, each of which needs to be an integer; it simply returns the sum of all its arguments. Read test2a() to see examples.

tomiddle is a function which should use a regular expression to match its input argument; this is a challenging problem (because regular expressions are complicated to define properly).

Rock is a class which implements two interfaces, Hardness and Gravity. Read test4a() and test4b() to see what is expected; the methods can be anything that satisfies the tests. The test4c() should pass automatically (it just shows checking that Rock has the interfaces).

source code file: // leave these interfaces alone, they are used // later in the tests interface Hardness { fun scratch(o:Int): Boolean fun meltpoint(): Int } interface Gravity { fun density(): Int fun leadconversion(elem: String): String } // infix function "wif" defined for strings infix fun String.wif(fixes:String): String { return "wrong answer" } // total function just does a sum of all its arguments, // which are supposed to be integers fun total(): Int { return -1 } // tomiddle(s:String) uses a regular expression // to test whether string s consists of three "words" // with the word "to" in the middle, and all whitespace // characters (blank, tab, newline, etc) are ignored fun tomiddle(s:String): Boolean { return false } // Rock class has to implement some interfaces class Rock(val name: String, var spdense:Int, val meltpt: Int): Hardness, Gravity { } 

Test code file

import org.junit.Test import org.junit.Assert.* class Sep7Test { @Test fun test1a() { assertEquals("++surround++", "surround" wif "++") assertEquals("xx", "" wif "x") assertEquals("time to time", " to " wif "time") } @Test fun test2a() { assertEquals(6,total(1,2,3)) assertEquals(10,total(1,2,3,4)) assertEquals(-5,total(-1,-1,-1,-1,-1)) // make N into array with 1, 2, 3, ..., 20 val N = (1..20).toList().toTypedArray().toIntArray() assertEquals(210,total(*N)) } @Test fun test3a() { assertEquals(false, tomiddle("testing one two")) assertEquals(false, tomiddle("ready to go fishing")) assertEquals(false, tomiddle("a to")) assertEquals(false, tomiddle("")) } @Test fun test3b() { assertEquals(true, tomiddle("a to b")) assertEquals(true, tomiddle("aa to bb")) assertEquals(true, tomiddle(" try to \t solve ")) // next one has newline characters (but these are whitespace) assertEquals(true, tomiddle("""whatifcase to try """)) } @Test fun test4a() { val v = Rock("Granite",7, 2500) assertEquals("Rock","$v") assertEquals(7,v.density()) assertEquals("",v.leadconversion("crystal")) assertEquals(2500,v.meltpoint()) } @Test fun test4b() { val v = Rock("Calcite",5,1800) assertEquals("Rock","$v") assertEquals(5,v.density()) assertEquals("",v.leadconversion("crystal")) assertEquals(1800,v.meltpoint()) } @Test fun test4c() { val v = Rock("Granite",7, 2500) assertTrue(v is Rock) assertTrue(v is Gravity) assertTrue(v is Hardness) } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!