依据分数范围划定等级

我们依据:

91-100分,[91,100],划分等级A;

81-90分,[81,90],划分等级B;

71-80分,[81,90],划分等级C;

61-70分,[81,90],划分等级E;

0-60分,[81,90],划分等级F;

package com.mytest.guava.common;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Test;

import com.google.common.collect.Range;
import com.google.common.collect.RangeMap;
import com.google.common.collect.TreeRangeMap;

/**
 * 范围等级用例
 * @author lifeng
 *
 */
public class RangeMapTest {

	@Test
	public void testRangeMap () {
	    RangeMap<Integer, String> gradeScale = TreeRangeMap.create();
	    gradeScale.put(Range.closed(0, 60), "F");
	    gradeScale.put(Range.closed(61, 70), "D");
	    gradeScale.put(Range.closed(71, 80), "C");
	    gradeScale.put(Range.closed(81, 90), "B");
	    gradeScale.put(Range.closed(91, 100), "A");
	    
	    assertThat(gradeScale.get(77)).isEqualTo("C");
	    assertThat(gradeScale.get(90)).isEqualTo("B");
	}
}


你可能感兴趣的:(guava,计算,分数,RangeMap,分数等级,分数范围)