2 * Copyright 2000-2016 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.openapi.vcs.ui
18 import com.intellij.testFramework.UsefulTestCase
19 import com.intellij.ui.Gray
22 class ColorGeneratorTest : UsefulTestCase () {
23 fun testLineGeneration() {
25 assertEquals(count + 2, generate(Color.BLACK, Color.WHITE, count).size)
28 assertOrderedEquals(generate(Gray._100, Gray._200, 0), listOf(Gray._100, Gray._200))
29 assertOrderedEquals(generate(Gray._100, Gray._200, 1), listOf(Gray._100, Gray._150, Gray._200))
30 assertOrderedEquals(generate(Gray._100, Gray._200, 3), listOf(Gray._100, Gray._125, Gray._150, Gray._175, Gray._200))
32 assertOrderedEquals(generate(Color(0, 100, 200), Color(200, 100, 0), 1), listOf(Color(0, 100, 200), Color(100, 100, 100), Color(200, 100, 0)))
35 fun testChainLineGeneration() {
36 for (anchorCount in 0..5) {
37 val anchors = generate(Color.BLACK, Color.WHITE, anchorCount)
39 val generated = generateChain(count, anchors)
40 assertContainsOrdered(generated, anchors)
44 assertOrderedEquals(generateChain(0, Gray._100, Gray._200), listOf(Gray._100, Gray._200))
45 assertOrderedEquals(generateChain(1, Gray._100, Gray._200), listOf(Gray._100, Gray._150, Gray._200))
46 assertOrderedEquals(generateChain(3, Gray._100, Gray._200), listOf(Gray._100, Gray._125, Gray._150, Gray._175, Gray._200))
48 assertOrderedEquals(generateChain(0, Gray._0, Gray._100, Gray._200), listOf(Gray._0, Gray._100, Gray._200))
49 assertOrderedEquals(generateChain(1, Gray._0, Gray._100, Gray._200), listOf(Gray._0, Gray._50, Gray._100, Gray._150, Gray._200))
50 assertOrderedEquals(generateChain(3, Gray._0, Gray._100, Gray._200), listOf(Gray._0, Gray._25, Gray._50, Gray._75, Gray._100, Gray._125, Gray._150, Gray._175, Gray._200))
52 assertOrderedEquals(generateChain(1, Color(0, 100, 200), Color(200, 100, 0)), listOf(Color(0, 100, 200), Color(100, 100, 100), Color(200, 100, 0)))
53 assertOrderedEquals(generateChain(1, Color(0, 100, 200), Color(0, 0, 0), Color(200, 100, 0)), listOf(Color(0, 100, 200), Color(0, 50, 100), Color(0, 0, 0), Color(100, 50, 0), Color(200, 100, 0)))
56 fun generate(color1: Color, color2: Color, count: Int) = ColorGenerator.generateLinearColorSequence(color1, color2, count)
57 fun generateChain(count: Int, vararg colors: Color) = ColorGenerator.generateLinearColorSequence(colors.asList(), count)
58 fun generateChain(count: Int, colors: List<Color>) = ColorGenerator.generateLinearColorSequence(colors, count)