Commit 7317716c authored by h2b's avatar h2b

Tests added.

parent fb9904a6
......@@ -44,15 +44,13 @@ class Cell private (private val width: Int, private val height: Int) {
* @return the resulting top-left pixel position
*/
def fit (w: Int, h: Int, o: Cell.Orientation = Cell.defaultOrientation): Pixel = {
var x = 0
var y = 0
o.horizontal match {
case Left x = 0
case HCenter x = (width -w)/2
val x = o.horizontal match {
case Left 0
case HCenter (width -w)/2
case Right width-w
}
o.vertical match {
case Top y = 0
val y = o.vertical match {
case Top 0
case VCenter (height-h)/2
case Bottom height-h
}
......
/*
SimGraf - A Simple Scala Graphics Library
Copyright 2016-2017 Hans-Hermann Bode
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package de.h2b.scala.lib.simgraf.layout
import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
import Cell.HorizontalOrientation._
import Cell.VerticalOrientation._
import de.h2b.scala.lib.simgraf.Pixel
@RunWith(classOf[JUnitRunner])
class CellTest extends FunSuite {
val cell = Cell(1000, 1000)
test("fitting default orientation") {
assertResult(Pixel(450, 450))(cell.fit(100, 100))
}
test("fitting arbitrary orientations") {
assertResult(Pixel(0, 0))(cell.fit(100, 100, Cell.Orientation(Left, Top)))
assertResult(Pixel(450, 450))(cell.fit(100, 100, Cell.Orientation(HCenter, VCenter)))
assertResult(Pixel(900, 900))(cell.fit(100, 100, Cell.Orientation(Right, Bottom)))
}
}
Markdown is supported
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